제출 #876432

#제출 시각아이디문제언어결과실행 시간메모리
876432arkash707Knapsack (NOI18_knapsack)C++17
37 / 100
2 ms504 KiB
#include<iostream> #include<vector> using namespace std; int s, n; //good: {price, weight, quantity} int a[100001][3]; long long solve() { long long dp[s+1]; for (int i=0; i<=s; i++) dp[i] = -1; dp[0] = 0; long long res = 0; for (int i=0; i<n; i++) { int p = a[i][0], w = a[i][1], q = a[i][2]; for (int j=s; j>=0; j--) { if (dp[j] == -1) continue; for (int k=0; k<=q; k++) { int index = j+1L*w*k; if (index > s) continue; dp[index] = max(dp[index], dp[j] + 1L*p*k); res = max(res, dp[index]); } } } return res; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif cin >> s >> n; for (int i=0; i<n; i++) { for (int j=0; j<3; j++) { cin >> a[i][j]; } } cout << solve() << "\n"; }
#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...