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 ll long long
#define pii pair<int,int>
#define fi first
#define se second
const int N = 2e3 + 5;
vector<pii>vec[N];
ll dp[N][N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int s,n;
cin >> s >> n;
for (int i = 1; i <= n; i++) {
int v,w,k;
cin >> v >> w >> k;
vec[w].push_back({v,k});
}
for (int i = 1; i <= 2000; i++)
sort(vec[i].begin(),vec[i].end(),greater<pii>());
ll ans = 0;
for (int i = 1; i <= 2000; i++)
for (int j = 1; j <= s; j++) {
dp[i][j] = dp[i - 1][j];
ll sumW = 0,sumV = 0;
for (auto x: vec[i]) {
int num = x.se,v = x.fi;
for (int z = 1; z <= num; z++) {
sumV += v,sumW += i;
if (sumW > j) break;
dp[i][j] = max(dp[i][j],dp[i - 1][j - sumW] + sumV);
}
if (sumW > j) break;
}
ans = max(ans,dp[i][j]);
}
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... |