Submission #1188102

#TimeUsernameProblemLanguageResultExecution timeMemory
1188102abcd1234Knapsack (NOI18_knapsack)C++20
73 / 100
1095 ms5892 KiB
#include <iostream> #include <vector> using namespace std; int main() { int s, n; cin >> s >> n; vector<vector<long long>> store(n, vector<long long>(3)); vector<bool> processed(s + 1, false); long long ans = 0; processed[0] = true; for(int i = 0; i < n; i++) { cin >> store[i][0] >> store[i][1]; long long temp; cin >> temp; store[i][2] = min(s / store[i][1], temp); } vector<long long> dp(s + 1, 0); for(int i = 0; i < n; i++) { while(store[i][2] > 0 ) { for(int j = s; j >= store[i][1]; j--) { if(processed[j - store[i][1]]) { dp[j] = max(dp[j - store[i][1]] + store[i][0], dp[j]); ans = max(dp[j], ans); processed[j] = true; } } store[i][2]--; } } cout << ans << endl; }
#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...