Submission #526434

#TimeUsernameProblemLanguageResultExecution timeMemory
526434ertoKnapsack (NOI18_knapsack)C++17
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> typedef long long int ll; #define INF ll(1e9 + 7) #define N (ll)2e2 + 5 using namespace std; void solve(){ ll s, n, g,t; bool bb=0; cin >> s >> n; ll v[n+1], w[n+1], k[n+1], dp[n+2][s+2]; memset(dp, 0, sizeof(dp)); for(int i=1; i<=n; i++){ cin >> v[i] >> w[i] >> k[i]; } for(int i=1; i<=n; i++){ t=0; for(int j=1; j<=s; j++){ dp[i][j] = dp[i-1][j]; g = j-w[i]; if(g>=0 && ((dp[i][g] + v[i]) > max(dp[i][j], dp[i-1][g] + v[i]))){ ++t; if(t <= k[i]){ dp[i][j] = dp[i][g] + v[i]; bb=1; } } else{ t= 0; } if(g>=0 && !bb){ if(dp[i-1][g] + v[i] > max(dp[i][g], dp[i][j]))t++; dp[i][j] = max(dp[i][g], max(dp[i-1][g] + v[i], dp[i][j])); } cout<<t; bb=0; } cout<<'\n'; } for(int i=1; i<=n; i++){ for(int j=1; j<=s; j++){ cout<<dp[i][j]; } cout<<'\n'; } cout<<dp[n][s]; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; //cin>>T; while (T--){ solve(); } }
#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...