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 <vector>
#include <cstring>
#include <algorithm>
#include <climits>
using namespace std;
const int MAXN = 2003;
int dp[MAXN];
vector<vector<int>> items(2003);
int main(){
for(int i =0; i < MAXN; i++)dp[i]=0;
int s,n; cin >> s >> n;
for(int i = 0; i < n; i++){
int v,w,k; cin >> v >> w >> k;
for(int i = 0; i < s/w; i++){
if(i >= k)items[w].push_back(v);
}
}
for(int i =0; i <= s; i++)sort(items[i].begin(),items[i].end(),greater<int>());
for(int i = 1; i <= s; i++){ // item ind
for(int j = 0; j < s/i; j++){ //num of items taken
for(int k = s; k >= i; k--){
dp[k] = max(dp[k], dp[k-i]+items[i][j]);
}
}
}
cout << dp[s] << endl;
}
# | 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... |