Submission #958753

#TimeUsernameProblemLanguageResultExecution timeMemory
958753lalig777Knapsack (NOI18_knapsack)C++14
12 / 100
1 ms348 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long int ll; int main(){ int n, s; cin>>s>>n; vector<vector<ll>>dp(2, vector<ll>(s+1, 0)); for (int i=0; i<n; i++){ int v, w, k; cin>>v>>w>>k; int kini=k; for (int j=1; j<s+1; j++){ if (j>=w and k>0){ if (dp[0][j]<dp[1][j-w]+v){ k--; dp[1][j]=dp[1][j-w]+v; }else dp[1][j]=max(dp[0][j], dp[1][j-1]); if (dp[1][j]==dp[0][j]) k=kini; }else if (j>=w){ dp[1][j]=max(dp[0][j-w]+v, max(dp[0][j], dp[1][j-1])); if (dp[1][j]==dp[0][j]) k=kini; else if (dp[1][j]==dp[0][j-w]+v) k=kini-1; }else dp[1][j]=dp[0][j]; }swap(dp[0], dp[1]); }cout<<dp[0][s]<<endl; return 0; }
#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...