Submission #867429

#TimeUsernameProblemLanguageResultExecution timeMemory
867429Kak008723Knapsack (NOI18_knapsack)C++14
100 / 100
683 ms2680 KiB
//knapsack.c #include<stdio.h> int main() { int s, n; int dp[2001] = {0}; scanf("%d%d", &s, &n); //s = 2000, n = 100000; for (int i = 0; i < n; ++i) { int v, w, k; scanf("%d%d%d", &v, &w, &k); //v = 1000000, w = 1, k = 1000000000; for (int r = 0; r < w; ++r) { int dq[2001][2]; int head = 0, tail = 0; for (int q = 0, j = r; j <= s; ++q, j += w) { int mn = q; if (mn > k) { mn = k; // min(q, k) } while (tail - head > 0 && dq[head][1] < q - mn) { ++head; } while (tail - head > 0 && dq[tail - 1][0] <= dp[j] - q * v) { --tail; } dq[tail][0] = dp[j] - q * v; dq[tail][1] = q; ++tail; dp[j] = dq[head][0] + q * v; } } } printf("%d\n", dp[s]); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  scanf("%d%d", &s, &n);
      |  ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d%d%d", &v, &w, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...