Submission #692462

#TimeUsernameProblemLanguageResultExecution timeMemory
692462aedmhsnKnapsack (NOI18_knapsack)C++17
0 / 100
26 ms32460 KiB
#include <bits/stdc++.h> using namespace std; #define A first #define B second #define MP make_pair #define ms(a, x) memset(a, x, sizeof(a)) #define boost() ios_base::sync_with_stdio(false); cin.tie(); cout.tie() typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long double, long double> pld; const int INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1); const int mxN=2e3+5; vector <pii> withw[mxN]; int dp[mxN][mxN]={}; int main(){ int s, n; cin >> s >> n; for(int i=0; i<n; i++){ int v, w, k; cin >> v >> w >> k; withw[w].push_back(MP(v, k)); } for(int i=1; i<=mxN; i++){ sort(withw[i].begin(), withw[i].end()); for(int j=1; j<=s; j++){ dp[i][j] = dp[i-1][j]; int totalval=0, totalw=0; for(auto [val, amnt]:withw[i]){ int temp=1; while(temp <= amnt && j >= totalw){ totalval+=val; totalw+=i; dp[i][j] = max(dp[i][j], dp[i-1][j-totalw]+totalval); temp++; } } } } cout << dp[mxN][s]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:52:19: warning: array subscript 2005 is above array bounds of 'int [2005][2005]' [-Warray-bounds]
   52 |     cout << dp[mxN][s];
      |             ~~~~~~^
knapsack.cpp:26:5: note: while referencing 'dp'
   26 | int dp[mxN][mxN]={};
      |     ^~
#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...