제출 #719608

#제출 시각아이디문제언어결과실행 시간메모리
719608JANCARAPANKnapsack (NOI18_knapsack)C++17
29 / 100
2 ms340 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long #define fi first #define se second #define pb push_back #define all(a) (a).begin(), (a).end() #define sz(a) (long long) a.size() #define endl '\n' #define dbg(a) cerr << #a << " = " << a << endl; #define print(a) for (auto x : a) cerr << x << " "; cerr << endl; const long long INF = 1e18, MOD = 1e9 + 7; void solve(){ int s, n; 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]; } vector<ll> dp(s + 1); for (int i = 0; i < n; i++) { vector<ll> already(s + 1), ndp(s + 1); for (int j = w[i]; j <= s; j++) { if (dp[j - w[i]] + v[i] > dp[j]) { ndp[j] = dp[j - w[i]] + v[i]; already[j] = 1; } if (ndp[j - w[i]] + v[i] > ndp[j] && already[j - w[i]] + 1 <= k[i]) { ndp[j] = ndp[j - w[i]] + v[i]; already[j] = already[j - w[i]] + 1; } if (ndp[j - 1] > ndp[j]) { ndp[j] = ndp[j - 1]; already[j] = already[j - 1]; } } for (int j = w[i]; j <= s; j++) { dp[j] = max(dp[j], ndp[j]); } //print(dp) } cout << dp[s] << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int tt = 1; //cin >> tt; while (tt--) { 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...