Submission #1319422

#TimeUsernameProblemLanguageResultExecution timeMemory
1319422f0rswornKnapsack (NOI18_knapsack)C++20
73 / 100
1096 ms16060 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll dp[2001];

int main() {
  int S, n;
  scanf("%d%d", &S, &n);
  memset(dp, 0, sizeof(dp));
  vector<ll> val, weights;
  for (int i = 0; i < n; ++i) {
    int v, w, k;
    scanf("%d%d%d", &v, &w, &k);
    int cnt = 1;
    while (k > 0) {
      int take = min(cnt, k);
      val.push_back(1LL * v * take);
      weights.push_back(1LL * w * take);
      k -= take;
      cnt <<= 1;
    }
  }
  int N = val.size();
  for (int i = 0; i < N; ++i) {
    for (int s = S; s >= weights[i]; --s) {
      dp[s] = max(dp[s], val[i] + dp[s - weights[i]]);
    }
  }
  printf("%lld\n", dp[S]);
  return 0;
}

Compilation message (stderr)

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