| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1344761 | 29avaz | Knapsack (NOI18_knapsack) | C++20 | 371 ms | 18812 KiB |
#include <bits/stdc++.h>
using namespace std;
int s, n;
struct items{
int v, w, k;
}item[100005];
int dp[100005][2005];
int main() {
scanf("%d %d", &s, &n);
set<int> weight;
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &item[i].v, &item[i].w, &item[i].k);
weight.insert(item[i].w);
}
map<int, vector<pair<int, int>>> a; // group by weight
for (int i = 0; i < n; i++) {
a[item[i].w].push_back({item[i].v, item[i].k});
}
for (int i = 1; i <= weight.size(); i++) {
int w = *next(weight.begin(), i - 1);
sort(a[w].begin(), a[w].end(), greater<pair<int, int>>());
for (int j = 0; j <= s; j++) {
dp[i][j] = dp[i - 1][j];
long long w_sum = 0, v_sum = 0;
int used = 0;
int num = 0;
while (num < a[w].size() && (w_sum + w) <= j) {
w_sum += w;
v_sum += a[w][num].first;
dp[i][j] = max(dp[i][j], dp[i - 1][j - w_sum] +(int)v_sum);
used++;
if (used >= a[w][num].second) {
used = 0;
num++;
}
}
}
}
int ans = 0;
for(int i = 1; i <= weight.size(); i++) {
for (int j = 0; j <= s; j++) {
ans = max(ans, dp[i][j]);
}
}
printf("%d", ans);
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... | ||||
