Submission #700202

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