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;
int dp[2001];
pair<pair<int,int>,int> a[(int)1e6+1];
int pref[2001][2001];
int lst[2001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s, n; cin >> s >> n;
for(int i=0;i<n;i++){
cin >> a[i].first.first >> a[i].first.second;
cin >> a[i].second;
}
sort(a, a+n);
for(int i=n-1;i>=0;i--){
//cout << lst[a[i].first.second] << ' ';
int tmp = min(lst[a[i].first.second]+a[i].second, s/a[i].first.second);
for(int j = lst[a[i].first.second]+1; j<=tmp ;j++){
pref[a[i].first.second][j]=pref[a[i].first.second][j-1];
pref[a[i].first.second][j]+=a[i].first.first;
lst[a[i].first.second]=j;
}
//lst[a[i].first.second]=min(s, lst[a[i].first.second]+a[i].second);
}
for(int i=1;i<=s;i++){
for(int j=s;j>=0;j--){
for(int x=lst[i]; x>=1; x--){
if(j+x*i<= s){
dp[j+x*i]=max(dp[j+x*i],dp[j]+pref[i][x]);
}
}
}
}
cout << *max_element(dp,dp+s+1) << '\n';
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... |