Submission #862290

#TimeUsernameProblemLanguageResultExecution timeMemory
862290eric_geKnapsack (NOI18_knapsack)C++14
73 / 100
1088 ms4080 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; #define F0R(i, a, b) for (int i = (a); i < (b); i++) #define FOR(i, a) F0R(i, 0, a) #define f first #define s second ll cx[] = {0, 1, 0, -1}; ll cy[] = {1, 0, -1, 0}; const ll INF = 1e9 + 7; struct item { ll p; ll w; ll amount; }; // auto start = chrono::steady_clock::now(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll t, n; cin >> t >> n; vector<item> v(n+1); for (ll i = 1; i <= n; i++) cin >> v[i].p >> v[i].w >> v[i].amount; vector<ll> dp(t+1, 0); ll ans = 0; for (ll i = 1; i <= n; i++) { ll times = min(v[i].amount, (t / v[i].w)); for (ll j = 0; j < times; j++) { for (ll k = t; k >= 0; k--) { if (dp[k] > 0 && k + v[i].w <= t) { dp[k + v[i].w] = max(dp[k + v[i].w], dp[k] + v[i].p); ans = max(ans, dp[k + v[i].w]); } if (k == v[i].w) { dp[k] = max(dp[k], v[i].p); ans = max(ans, dp[k]); } } } } cout << ans; // cout << "\n"; // auto end = chrono::steady_clock::now(); // auto diff = end - start; // cout << chrono::duration<double, milli>(diff).count() << " ms" << endl; 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...