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;
#define int long long
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
int n, W, dp[2010][2010];
vector<pair<int,int>> weight[2010];
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> W >> n;
for(int i = 0; i < n; i++){
int v, w, k; cin >> v >> w >> k;
weight[w].pb({v,k});
}
for(int i = 0; i <= W; i++) sort(all(weight[i])), reverse(all(weight[i]));
for(int i = 0; i <= W; i++)
for(int j = 0; j <= W; j++)
dp[i][j] = (j==0?0ll:-(int)1e18);
for(int i = 1; i <= W; i++){
for(int j = 0; j <= W; j++){
dp[i][j] = max(dp[i][j], dp[i-1][j]);
int mx_k = j/i, val = 0, k = 0;
for(auto u : weight[i]){
if(k>=mx_k) break;
while(u.se-- and k<mx_k){
val+=u.fi, k++;
dp[i][j] = max(dp[i][j], dp[i-1][j-k*i]+val);
}
}
}
}
int ans = 0; for(int i = 0; i <= W; i++) ans = max(ans, dp[W][i]);
cout << ans << "\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... |