이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define nl '\n'
using ll = long long;
void maxself(int &a, int b) {
a = max(a, b);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int S, N; cin >> S >> N;
vector<int> quantiMax(S+1); for (int a=1; a<=S; a++) quantiMax[a] = (S+a-1)/a;
vector<vector<pair<int, int>>> infos(S+1);
int v, w, k;
for (int a=0; a<N; a++) {
cin >> v >> w >> k;
if (w > S) continue;
infos[w].pb({v, k});
}
for (int a=1; a<=S; a++) sort(infos[a].begin(), infos[a].end());
vector<int> values, weights;
values.pb(0); weights.pb(0);
for (int a=1; a<=S; a++) {
while(infos[a].size() && quantiMax[a]--) {
int value = infos[a][infos[a].size()-1].first; infos[a][infos[a].size()-1].second--;
values.pb(value);
weights.pb(a);
if (infos[a][infos[a].size()-1].second <= 0) infos[a].pop_back();
}
}
int dp[(int) values.size()][S+1];
memset(dp, 0, sizeof(dp));
for (int n=1; n < (int) values.size(); n++) {
for (int w = 0; w <= S; w++) {
if (w - weights[n] >= 0)
maxself(dp[n][w], dp[n-1][w - weights[n]] + values[n]);
maxself(dp[n][w], dp[n-1][w]);
}
}
cout << dp[values.size()-1][S];
}
# | 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... |