Submission #868563

#TimeUsernameProblemLanguageResultExecution timeMemory
868563PbezzKnapsack (NOI18_knapsack)C++17
73 / 100
157 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair const ll MAXN = 1e6+5; const ll INF = 1e5+5; const ll MOD = 1e9+7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll s,n; cin>>s>>n; ll v,w,k; ll obj[n+1][3]; for(int i=1;i<=n;i++){ cin>>v>>w>>k; obj[i][0]=v; obj[i][1]=w; obj[i][2]=k; } ll dp[n+1][s+1]; for(int j=0;j<=s;j++)dp[0][j]=0; for(int i=1;i<=n;i++){ for(int j=0;j<=s;j++){ dp[i][j]=0; for(ll freq=0;freq<=obj[i][2];freq++){ if(j-freq*obj[i][1]<0)break; dp[i][j] = max(dp[i][j] , dp[i-1][j-freq*obj[i][1]]+freq*obj[i][0]); } } } cout<<dp[n][s]<<'\n'; 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...