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>
#include <queue>
using namespace std;
const int MAXN = 2003;
long long dp[MAXN];
vector<priority_queue<int>> items(MAXN);
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;
int smol = min(s/w, k);
for(int j = 0; j < smol; j++)items[w].push(v);
}
long long maxmax = -1;
for(int i = 1; i <= s; i++){ // item ind
int smol = s/i;
while(items[i].size() && smol){
//num of items taken
auto l = items[i].top();
items[i].pop();
smol--;
for(int k = s; k >= i; k--){
dp[k] = max(dp[k], dp[k-i]+l);
}
}
}
for(int i = 0; i <= s; i++)maxmax = max(maxmax,dp[i]);
cout << maxmax << 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... |