이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const int mod = 998244353;
const int inf = 1e9;
//-------------------KarginCode------------------------\\
const int N = 100005, M = 2005;
int v[N], w[N], k[N];
ll dp[M];
pqueue<pair<int, int>> pq[M];
void KarginSolve() {
int s, n;
cin >> s >> n;
for (int i = 0; i < n;i++) {
cin >> v[i] >> w[i] >> k[i];
pq[w[i]].push({ v[i],k[i] });
}
for (int i = 1;i <= s;i++) {
int c = s / i;
while (!pq[i].empty() && c) {
int vv = pq[i].top().first, kk = pq[i].top().second; pq[i].pop();
kk = min(kk, c);
c -= kk;
for (int j = s;j >= 0;j--) {
for (int x = 1;x <= kk;x++) {
if (j + i * x <= s) dp[j + i * x] = max(dp[j + x * i], dp[j] + x * vv);
}
}
}
}
ll ans = 0;
for (int i = 0;i <= s;i++) ans = max(ans, dp[i]);
cout << ans << '\n';
}
int main() {
//Usaco
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
knapsack.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
knapsack.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
knapsack.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# | 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... |