| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1259870 | ashraful_alam_ | Knapsack (NOI18_knapsack) | C++20 | 34 ms | 2888 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long w, n;
cin >> w >> n;
vector<priority_queue<pair<long long, long long>>> a(w + 1);
for (long long i = 0; i < n; i++) {
long long v, x, y;
cin >> v >> y >> x;
a[y].push({v, x});
}
vector<long long> d(w + 1);
for (long long i = 1; i <= w; i++) {
long long f = w / i;
while (!a[i].empty() && f) {
auto [v, x] = a[i].top();
a[i].pop();
if (x > f) x = f;
f -= x;
for (long long j = 0; j < x; j++) {
for (long long k = w; k >= i; k--) {
d[k] = max(d[k], d[k - i] + v);
}
}
}
}
cout << *max_element(d.begin(), d.end());
}
| # | 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... | ||||
