제출 #638017

#제출 시각아이디문제언어결과실행 시간메모리
638017zandlerKnapsack (NOI18_knapsack)C++17
73 / 100
213 ms752 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int dp[2001]; // first i considered, j space taken int c[2001]; int v[2001]; int k[2001]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int s, n; cin >> s >> n; for(int i=0;i<n;i++){ cin >> v[i] >> c[i] >> k[i]; k[i]=min(k[i], s/c[i]); } for(int i=0;i<n;i++){ for(int j=s;j>=0;j--){ for(int x=k[i]; x>=1; x--){ if(j+x*c[i] <= s){ dp[j+x*c[i]]=max(dp[j+x*c[i]],dp[j]+v[i]*x); } } } } cout << *max_element(dp,dp+s+1) << '\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...