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;
using ll = long long;
using ii = pair<int, int>;
using aa = array<int,3>;
const int N = 1e6+5;
const int INF = 1e9;
ll dp[2005][2005];
vector<ii> m[2005];
int pre[2005][2005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,s;
cin >> s >> n;
for(int i=1;i<=s;i++) {
for(int j=1;j<=s;j++) dp[i][j]=0;
}
for(int i=1;i<=n;i++) {
int v,w,k;
cin >> v >> w >> k;
m[w].push_back({v,k});
}
for(int i=1;i<=s;i++) {
sort(m[i].begin(),m[i].end(),greater<>());
}
for(int i=1;i<=s;i++) {
int cur=0;
for(ii x:m[i]) {
int t=cur;
cur+=x.second;
cur=min(cur,s/i);
for(int j=t+1;j<=cur;j++) {
pre[i][j]=pre[i][j-1]+x.first;
}
if(cur>=s/i) break;
}
}
ll ans=0;
for(int i=1;i<=s;i++) {
for(ll j=1;j<=s;j++) {
for(int k=1;i*k<=j;k++) {
dp[i][j]=max(dp[i][j],dp[i-1][j-i*k]+pre[i][k]);
ans=max(ans,dp[i][j]);
}
dp[i][j]=max(dp[i][j],dp[i-1][j]);
//cout << dp[i][j] << ' ';
}
//cout << endl;
}
cout << ans;
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... |