Submission #1116290

#TimeUsernameProblemLanguageResultExecution timeMemory
1116290TAFHKnapsack (NOI18_knapsack)C++17
73 / 100
1071 ms3920 KiB
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < n; i++) #define ull unsigned long long #define ll long long #define SPEED \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) using namespace std; const int N = 1000 + 13; const int maxa = 1e6 + 13; const ll mod = 998244353; void prestart() {} ll dp[maxa]; void start() { int s, n; cin >> s >> n; ll v[n], w[n], k[n]; forn(i, n) { cin >> v[i]; cin >> w[i]; cin >> k[i]; } for (int i = 0; i < n; i++) { for (int j = s; j >= 0; j--) { for(int l = 0; l <= min(k[i], j / w[i]); l++) { dp[j] = max(dp[j], dp[j - w[i] * l] + v[i] * l); } } } cout << dp[s] << "\n"; } signed main() { SPEED; int t = 1; prestart(); // cin >> t; while (t--) { start(); } }
#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...