| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1179482 | GoBananas69 | Knapsack (NOI18_knapsack) | C++20 | 1 ms | 328 KiB |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
cin.tie(0)->sync_with_stdio(0);
int s, n;
cin >> s >> n;
if (s < 0 || n <= 0) {
cout << 0 << '\n';
return 0;
}
vector<ll> v(1, 0), w(1, 0);
for (int i = 0; i < n; ++i) {
int a, b, c;
cin >> a >> b >> c;
int k = 1;
while (k <= c) {
w.push_back(b * k);
v.push_back(a * k);
c -= k;
k *= 2;
}
if (c > 0) {
w.push_back(b * c);
v.push_back(a * c);
}
}
n = v.size() - 1;
if (n == 0) {
cout << 0 << '\n';
return 0;
}
vector<vector<ll>> dp(2, vector<ll>(s + 1, 0));
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= s; ++j) {
if (w[i] > j) {
dp[1][j] = dp[0][j];
} else {
dp[1][j] = max(dp[0][j], v[i] + dp[0][j - w[i]]);
}
}
swap(dp[1], dp[0]);
}
cout << dp[0][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... | ||||
