| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 782032 | andecaandeci | Knapsack (NOI18_knapsack) | C++17 | 2 ms | 4308 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int lim = 100005;
int t, n, val[lim], cost[lim], freq[lim], dp[10005][2005];
vector<pair<int, int>> bycost[lim];
vector<pair<int, int>> item;
signed main() {
cin >> t >> n;
for (int i = 0; i < n; i++) {
cin >> val[i] >> cost[i] >> freq[i];
bycost[cost[i]].push_back({val[i], freq[i]});
}
for (int i = 1; i <= t; i++) {
sort(bycost[i].begin(), bycost[i].end(), greater<pair<int, int>>());
}
int total = 0, value = 0;
// item.push_back({0, 0});
for (int i = 1; i <= t; i++) {
total = 0;
value = 0;
for (auto j: bycost[i]) {
if (total >= t) break;
for (int k = 1; k <= j.second; k++) {
total += i;
value += j.first;
if (total >= t) break;
item.push_back({j.first, i});
}
}
}
// for (auto i: item) {
// cout << i.first << " " << i.second << endl;
// }
for (int i = 0; i < item.size(); i++) {
for (int j = 1; j <= t; j++) {
if (i-1 < 0) dp[i][j] = 0;
else dp[i][j] = dp[i-1][j];
if (j >= item[i].second) {
dp[i][j] = max(dp[i][j], dp[i-1][j-item[i].second]+item[i].first);
}
}
}
cout << dp[item.size()-1][t] << endl;
}컴파일 시 표준 에러 (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... | ||||
