Submission #464292

#TimeUsernameProblemLanguageResultExecution timeMemory
464292vbeeKnapsack (NOI18_knapsack)C++14
73 / 100
1094 ms1420 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define ii pair<int,int> #define vii vector<ii> #define vi vector<int> #define fi first #define se second #define TASK "" #define ll long long #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> #define pb push_back #define MASK(i) (1 << (i)) #define BIT(x, i) ((x >> (i)) & 1) using namespace std; const int oo = 1e9 + 7; const ll loo = (ll)1e18 + 7; const int N = 1e5 + 1; const int S = 2001; int dp[S], newdp[S], w[N], v[N], k[N], n, s; void maximize(int &a, int b){ if (a < b) a = b; } int main() { scanf("%d%d", &s, &n); for (int i = 1; i <= n; i++) scanf("%d%d%d", &v[i], &w[i], &k[i]); for (int i = 0; i < n; i++){ for (int sum = 0; sum <= s; sum++){ for (int z = 0; z <= k[i + 1]; z++){ if (sum + w[i + 1] * z > s) break; maximize(dp[sum + w[i + 1] * z], newdp[sum] + v[i + 1] * z); } swap(dp[sum], newdp[sum]); dp[sum] = 0; } } int res = 0; for (int i = 0; i <= s; i++) maximize(res, newdp[i]); printf("%d", res); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%d%d", &s, &n);
      |  ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:30:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  for (int i = 1; i <= n; i++) scanf("%d%d%d", &v[i], &w[i], &k[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...