Submission #973164

#TimeUsernameProblemLanguageResultExecution timeMemory
973164SeenSiravitKnapsack (NOI18_knapsack)C++14
73 / 100
1033 ms2820 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; const int mxN = 1e5 + 5 , mxS = 2000 + 5; int n,s; int v[mxN] , w[mxN] , k[mxN]; ll dp[mxS]; int main(){ ios::sync_with_stdio(0),cin.tie(0); cin>> s >> n; for(int i=1;i<=n;i++) cin>> v[i] >> w[i] >> k[i] , k[i] = min(k[i] , s/w[i]); for(int i=1;i<=n;i++){ for(int j=1;j<=k[i];j++){ for(int cap=s;cap>=w[i];cap--){ dp[cap] = max(dp[cap] , dp[cap - w[i]] + v[i]); } // printf("%d %d %d\n",i,j,dp[s]); } } cout<< dp[s]; 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...