Submission #462420

#TimeUsernameProblemLanguageResultExecution timeMemory
462420lto5Knapsack (NOI18_knapsack)C++14
73 / 100
1082 ms20420 KiB
#include <bits/stdc++.h> using namespace std; int n, m; long long w[100001], v[100001], a[100001], dp[2001]; vector < pair <long long, long long> > items = { {-1, -1} }; int main(){ cin >> m >> n; for(int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> a[i]; // i-th item for(int i = 1; i <= n; i++){ for(int j = 0; a[i] - (1LL << j) >= 0; j++) a[i] -= (1 << j), items.push_back({w[i] * (1LL << j), v[i] * (1 << j)}); if(a[i] > 0) items.push_back({w[i] * a[i], v[i] * a[i]}); } int num = (int)items.size() - 1; for(int i = 1; i <= num; i++) for(int j = m; j >= items[i].first; j--) dp[j] = max(dp[j], dp[j - items[i].first] + items[i].second); cout << dp[m]; return 0; }
#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...