Submission #700198

#TimeUsernameProblemLanguageResultExecution timeMemory
700198mariacichoszKnapsack (NOI18_knapsack)C++17
73 / 100
1087 ms1836 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 5; const int S = 2005; ll dp[S]; ll value[N]; int weight[N]; int amount[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, s; cin >> s >> n; for (int i = 0; i < n; i ++) cin >> value[i] >> weight[i] >> amount[i]; for (int i = 0; i < n; i ++){ ll v = value[i]; int w = weight[i], a = amount[i]; a = min(a, s / w); for (int j = s; j >= 0; j --){ for (int k = 1; k <= min(a, (s - j) / w); k ++){ dp[j + k * w] = max(dp[j + k * w], dp[j] + k * v); } } } ll ans = 0; for (int i = 0; i <= s; i ++) ans = max(ans, dp[i]); cout << ans << "\n"; }
#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...