이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define vr(v) v.begin(),v.end()
#define rv(v) v.rbegin(),v.rend()
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Davit cout.tie(NULL);
using namespace std;
//#include "algo/debug.h"
int main() {
Code
By
Davit
int S, n;
cin >> S >> n;
vector<int> V(n), W(n), K(n);
vector<vector<pair<int, int>>> by_weight(S + 5);
// map<int, vector<pair<int, int>>> by_weight;
for (int i = 0; i < n; i++) {
cin >> V[i] >> W[i] >> K[i];
K[i] = min(K[i], S / W[i]);
by_weight[W[i]].pb({V[i], K[i]});
}
vector<int> dp(S + 5, 0);
for (int x = 0; x <= S; x++) {
for (int y = 0; y < (int) by_weight[x].size(); y++) {
for (int cnt = 0; cnt < by_weight[x][y].ss; cnt++) {
for (int k = S; k >= 0; k--) {
if (k - x >= 0)dp[k] = max(dp[k], dp[k - x] + by_weight[x][y].ff);
}
}
}
}
int answer = 0;
for (int k = S; k >= 0; k--) {
answer = max(answer, dp[k]);
}
cout << answer << endl;
}
# | 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... |