| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1331396 | kride024 | Knapsack (NOI18_knapsack) | C++20 | 1 ms | 344 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long S, n;
cin >> S >> n;
vector<long long> dp(S + 1, 0);
for (int i = 0; i < n; i++) {
long long v, w, k;
cin >> v >> w >> k;
// Binary splitting
for (long long j = 1; j <= k; j <<= 1) {
long long take = min(j, k);
long long value = v * take;
long long weight = w * take;
// 0/1 knapsack transition (backward)
for (long long s = S; s >= weight; s--) {
dp[s] = max(dp[s], dp[s - weight] + value);
}
k -= take;
}
}
cout << dp[S] << "\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... | ||||
