제출 #985767

#제출 시각아이디문제언어결과실행 시간메모리
985767lftroqKnapsack (NOI18_knapsack)C++14
73 / 100
1060 ms16188 KiB
#include <bits/stdc++.h> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl '\n' using namespace std; void solve() { int s,n; cin >> s >> n; long long dp[s+1]={0}; vector<long long> v,w; for(int i=1;i<=n;i++) { int a,b,c; cin >> a >> b >> c; int p=1; while(c>=p) { c-=p; v.push_back(1ll*a*p); w.push_back(1ll*b*p); p<<=1; if(1ll*b*p>s) break; } if(c&&1ll*b*c<=s) { v.push_back(1ll*a*c); w.push_back(1ll*b*c); } } for(int i=0;i<(int)w.size();i++) for(int j=s;j>=w[i];j--) dp[j]=max(dp[j],dp[j-w[i]]+v[i]); cout << dp[s] << endl; } int main() { fastIO solve(); 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...