Submission #482477

#TimeUsernameProblemLanguageResultExecution timeMemory
482477IlsiyaKnapsack (NOI18_knapsack)C++17
73 / 100
444 ms34620 KiB
#include<bits/stdc++.h> using namespace std; typedef int ll; typedef vector<ll> vll; typedef vector<char> vch; typedef long double ld; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll s, n; cin >> s >> n; pair<pair<ll, ll>, ll> shop[n+1]; for (ll i = 1; i <= n; i++) { cin >> shop[i].first.first >> shop[i].first.second >> shop[i].second; } ll dp[2005][2005]; for (ll i = 0; i <= n; i++) { for (ll j = 0; j <= s; j++) { dp[i][j] = 0; } } for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= s; j++) { ll cou = 0; while (cou*shop[i].first.second <= j && cou <= shop[i].second) { dp[i][j] = max(dp[i][j], dp[i-1][j - cou * shop[i].first.second] + cou * shop[i].first.first); cou++; } } } ll ans = 0; for (ll i = 0; i <= n; i++) { for (ll j = 0; j <= s; j++) { ans = max(ans, dp[i][j]); } } 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...