Submission #1103904

#TimeUsernameProblemLanguageResultExecution timeMemory
1103904micro7Knapsack (NOI18_knapsack)C++17
0 / 100
1 ms424 KiB
#include <algorithm> #include <cstdio> using namespace std; constexpr int MAXN = 1e5, MAXS = 2000; int n; long long s; long long dp[MAXS + 1]; void add_01_item(long long v, long long w) { for (int i = s; i >= w; --i) dp[i] = max(dp[i], dp[i - s] + v); } int main() { scanf("%lld%d", &s, &n); while (n--) { long long v, w, k; scanf("%lld%lld%lld", &v, &w, &k); for (int i = 1; i <= k; i *= 2) { add_01_item(v * i, w * i); k -= i; } if (k) add_01_item(v * k, w * k); } printf("%lld", dp[s]); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%lld%d", &s, &n);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
knapsack.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%lld%lld%lld", &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...