제출 #682892

#제출 시각아이디문제언어결과실행 시간메모리
682892matuKnapsack (NOI18_knapsack)C++14
73 / 100
1067 ms1492 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1, S = 2e3+ 1; int n, s; //vector<vector<long long>> dp(N, vector<long long>(S)); vector<long long> dp1(S), dp2(S); vector<int> h(N), w(N), k(N); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for(int i = 1; i <= n; i++){ cin >> w[i] >> h[i] >> k[i]; } long long pra = h[1], car = w[1]; while(k[1] && pra <= s){ dp1[pra] = car; pra += h[1]; car += w[1]; k[1]--; } for(int i = 2; i <= n; i++){ for(int x = 1; x <= s; x++){ dp2[x] = max(dp2[x], dp1[x]); long long acum = h[i], pr = w[i], zaz = k[i]; while(acum <= s && zaz){ if(x >= acum && dp2[x] < dp1[x - acum] + pr){ dp2[x] = dp1[x - acum] + pr; } acum += h[i]; pr += w[i]; zaz--; } } swap(dp2, dp1); } long long ans = 0; for(int i = 1; i <= s; i++){ ans = max(ans, dp1[i]); } cout << ans; }
#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...