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 ll = long long;
#define pb push_back
using namespace std;
const int maxV = 2e3+5;
vector<ll> d[maxV];
int S,N;
ll f[maxV];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> S >> N;
for(int i = 1; i <= N; ++i){
ll v,w,k; cin >> v >> w >> k;
for(int j = 1; j <= k; j <<= 1){
if(w * j > S)break;
k -= j;
d[w*j].pb(v*j);
}
if(k > 0 && w * k <= S)d[w*k].pb(v*k);
}
for(int i = 1; i <= S; ++i){
if(d[i].size()){ //for each group of objects w/ weight = i
sort(d[i].begin(),d[i].end(),greater<int>());
//Consider only the first floor(S/W) objects
int num = min(S/i,(int)(d[i].size()));
for(int j = 0; j < num; ++j){
for(int k = S; k >= i; --k){
f[k] = max(f[k],f[k-i] + d[i][j]);
}
}
}
}
cout << f[S] << '\n';
}
# | 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... |