제출 #876422

#제출 시각아이디문제언어결과실행 시간메모리
876422arkash707Knapsack (NOI18_knapsack)C++17
37 / 100
2 ms464 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++) { if (1L*j+w*k > s) continue; dp[j+w*k] = max(dp[j+w*k], dp[j] + p*k); res = max(res, dp[j+w*k]); } } } return res; } int main() { 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...