이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
const int S = 2000;
ll s, n, v, w, k, id, cap;
vector<vector<ll>> dp;
vector<pair<ll, ll>> arr;
vector<vector<pair<ll,ll>>> a;
signed main() {
cin >> s >> n;
a.resize(S+5);
for (int i = 0; i < n; i++) {
cin >> v >> w >> k;
a[w].push_back({v, k});
}
for (int i = 1; i < S; i++) {
sort(a[i].rbegin(), a[i].rend());
cap = S / i, id = 0;
while (cap > 0 && id < (int) a[i].size()) {
for (int j = 0; j < min(cap, a[i][id].se); j++) {
arr.push_back({i, a[i][id].fi});
}
cap -= min(cap, a[i][id].se), id++;
}
}
dp.assign((int) arr.size(), vector<ll>(s+5));
for (int i = 0; i <= s; i++) {
if (i >= arr[0].fi) dp[0][i] = arr[0].se;
}
for (int i = 1; i < (int) arr.size(); i++) {
for (int j = 0; j <= s; j++) {
dp[i][j] = dp[i-1][j];
if (j >= arr[i].fi) dp[i][j] = max(dp[i][j], dp[i-1][j-arr[i].fi] + arr[i].se);
}
}
ll ans = 0;
for (int i = 0; i <= s; i++) {
ans = max(ans, dp[arr.size()-1][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... |