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;
typedef long long ll;
struct d1{
int v, w, k;
double r;
};
bool comp(d1 a, d1 b){
if(a.r==b.r) return a.w<b.w;
return a.r>b.r;
}
int main(){
int s, n; cin>>s>>n;
vector<d1> d(n);
for (int i=0; i<n; i++) {
cin>>d[i].v>>d[i].w>>d[i].k;
d[i].r=double(d[i].v)/d[i].w;
}
sort(d.begin(), d.end(), comp);
vector<ll> dp(s+1, -1);
dp[0]=0;
for (int i=0; i<n; i++){
for (int x=s; x>=0; x--){
if(dp[x]>=0){
for (int j=0; j<d[i].k && x+(j+1)*d[i].w<=s; j++){
dp[x+(j+1)*d[i].w]=max(dp[x]+(j+1)*d[i].v, dp[x+(j+1)*d[i].w]);
}
}
}
}
ll ans=0;
for (int i=0; i<=s; i++) ans=max(ans, dp[i]);
cout<<ans<<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... |