이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0) -> sync_with_stdio(0);
int S, N; cin >> S >> N;
vector<ll> value(S + 1, -1);
value[0] = 0;
for (int i = 0; i < N; i++) {
int v, w, c; cin >> v >> w >> c;
vector<ll> tmp = value;
for (int j = 0; j < w; j++) {
multiset<ll> ms;
for (int k = j; k < S - w + 1; k += w) {
int idx = (k - j) / w;
// cout << k << "\n";
// cout << ms.size() << "\n";
if (value[k] != -1) { ms.insert(value[k] - idx * v); }
// cout << ms.size() << "\n";
//now what
//erase idx - c
if (idx >= c) {
//we can't be erasing 0 every time bruh this is stupid
//
int ok = k - c * w;
int oidx = (ok - j) / w;
// cout << ok << endl;
// cout << value[i][ok] << endl;
// cout << *ms.begin() << endl;
// cout << value[i][ok] - oidx * v << endl;
// cout << endl;
// cout << "erasing: " << value[i][oidx] - oidx * v << "\n";
if (ms.find(value[ok] - oidx * v) != ms.end()) {
ms.erase(ms.find(value[ok] - oidx * v));
}
}
if (ms.empty()) { continue; }
ll best = *ms.rbegin();
// cout << best << endl;
tmp[k + w] = max(tmp[k + w], best + (idx + 1) * v);
}
}
value = tmp;
// cout << "\n";
}
ll ans = 0;
// for (int i = 0; i < N + 1; i++) {
// for (int j = 0; j < S; j++) {
// cout << value[i][j] << " ";
// }
// cout << "\n";
// }
for (int i = 0; i < S + 1; i++) {
ans = max(value[i], ans);
}
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... |