| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1341232 | kiengyt | Knapsack (NOI18_knapsack) | C++20 | 1 ms | 344 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int S_MAX = 100005;
ll dp[S_MAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s, n;
if (!(cin >> s >> n)) return 0;
for (int i = 0; i <= s; i++) dp[i] = 0;
for (int i = 0; i < n; i++) {
int v_i, w_i, k_i;
cin >> v_i >> w_i >> k_i;
if (w_i > s || k_i <= 0) continue;
for (int j = 1; k_i > 0; j <<= 1) {
int num = min(j, k_i);
ll V = (ll)num * v_i;
int W = num * w_i;
if (W <= s) {
for (int j_s = s; j_s >= W; j_s--) {
if (dp[j_s - W] + V > dp[j_s]) {
dp[j_s] = dp[j_s - W] + V;
}
}
}
k_i -= num;
}
}
ll ans = 0;
for (int j = 0; j <= s; j++) if (dp[j] > ans) ans = dp[j];
cout << ans;
return 0;
}| # | 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... | ||||
