This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |