제출 #1023633

#제출 시각아이디문제언어결과실행 시간메모리
1023633vjudge1Knapsack (NOI18_knapsack)C++17
29 / 100
2 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ff first #define ss second #pragma GCC optimize("O3") #pragma GCC target("avx2") const int inf = 1e9; signed main() { int n, s; cin >> s >> n; vector<int> v(n), w(n), k(n); for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } if(n == 1) { cout << min(s/w[0], k[0]) * v[0] << "\n"; return 0; } vector<int> dp(s + 1, 0); for (int i = 0 ; i < n; i++) { for (int j = s; j > 0; j--) { if (w[i] > j) continue; for (int kk = k[i]; kk > 0; kk--) { if (j - kk * w[i] < 0) { break; } dp[j] = max(dp[j], dp[j - kk * w[i]] + kk * v[i]); } } } int ans = 0; for (int i = 0; i < s + 1; i++) { ans = max(dp[i], ans); } 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...