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 <iostream>
#include <bits/stdc++.h>
using namespace std;
vector<int> value;
vector<int> weight;
vector<int> copies;
vector<long long> ans (4e3+4,-1);
vector<vector<int>> copiesdp(1e5+5, vector<int>(4e3+3));
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, x;
cin >> x >> n;
for(int i=0;i<n;i++){
int a,b,c;
cin >> a >> b >> c;
value.push_back(a);
weight.push_back(b);
copies.push_back(c);
}
ans[0]=0;
for(int i=0;i<n;i++){
for(int j=0;j<=x;j++){
if(copiesdp[i][j]==copies[i])
continue;
if(ans[j+weight[i]]<=ans[j]+value[i]){
ans[j+weight[i]]=ans[j]+value[i];
copiesdp[i][j+weight[i]]=copiesdp[i][j]+1;
}
}
}
cout << *(max_element(ans.begin(),ans.begin()+x+1));
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... |