# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1053985 | ssitaram | Knapsack (NOI18_knapsack) | C++17 | 56 ms | 68176 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
ll s, n; cin >> s >> n;
vector<vector<ll>> items(s + 1);
vector<tuple<ll, ll, ll>> init(n);
for (ll i = 0; i < n; ++i) {
cin >> get<0>(init[i]) >> get<1>(init[i]) >> get<2>(init[i]);
}
sort(init.rbegin(), init.rend());
for (ll i = 0; i < n; ++i) {
ll v = get<0>(init[i]);
ll w = get<1>(init[i]);
ll k = get<2>(init[i]);
while (items[w].size() <= s && k > 0) {
items[w].push_back(v);
--k;
}
}
vector<vector<ll>> best(s + 1, vector<ll>(s + 1));
for (ll i = 1; i <= s; ++i) {
for (ll j = 0; j <= s; ++j) {
best[i][j] = best[i - 1][j];
ll amnt = 0;
for (ll k = 0; k < items[i].size(); ++k) {
amnt += items[i][k];
if (j - (k + 1) * i < 0) break;
best[i][j] = max(best[i][j], best[i - 1][j - (k + 1) * i] + amnt);
}
}
}
cout << best[s][s] << '\n';
return 0;
}
컴파일 시 표준 에러 (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... |