# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1094991 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 37 ms | 3676 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/** DRAFT
placeholder
**/
#include "bits/stdc++.h"
using namespace std;
#define MULTI_TEST 0
#define IN "TASK.INP"
#define OUT "TASK.OUT"
// #define cerr if (false) cerr
using lint = long long;
constexpr int MOD = int(1e9) + 7; // 998244353;
constexpr int MAX = 0x3f3f3f3f;
constexpr lint LMAX = lint(1e18) + 5;
int test_case = 1;
#define all(a) begin(a), end(a)
void solve() {
// cerr << "Case #" << test_case++ << ":\n";
int goal, n;
cin >> goal >> n;
constexpr int W = 2000 + 5;
/// items[w] are items with weight w, each item is (value, count)
vector<array<int, 2>> items[W];
for (int i = 0, v, w, c; i < n; i++) {
cin >> v >> w >> c;
items[w].push_back({v, c});
}
vector<lint> dp(W);
for (int weight = 1; weight <= goal; weight++) {
if (items[weight].empty()) {
continue;
}
sort(all(items[weight]), greater<array<int, 2>>());
int i = 0;
for (int rep = 0; rep < goal / weight; rep++) {
for (int w = goal; w >= weight; w--) {
dp[w] = max(dp[w], dp[w - weight] + items[weight][i][0]);
}
items[weight][i][1]--;
if (items[weight][i][1] == 0) {
i++;
}
if (i == (int) items[weight].size()) {
break;
}
}
}
lint ans = *max_element(all(dp));
cout << ans;
}
signed main() {
if (fopen("iii.txt", "r")) {
freopen("iii.txt", "r", stdin);
freopen("ooo.txt", "w", stdout);
freopen("eee.txt", "w", stderr);
}
if (fopen(IN, "r")) {
freopen(IN, "r", stdin);
freopen(OUT, "w", stdout);
}
ios::sync_with_stdio(false);
cin.tie(nullptr);
cerr << __cplusplus << '\n';
int t = 1;
if (MULTI_TEST)
cin >> t;
while (t --> 0) {
solve();
cout << '\n';
}
cerr << '\n' << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
return 0;
}
/**
--------------------------------------------------
X INPUT X
--------------------------------------------------
--------------------------------------------------
X OUTPUT X
--------------------------------------------------
**/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |