| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1295562 | michaeltaranik | Knapsack (NOI18_knapsack) | C++17 | 172 ms | 327680 KiB |
#include <iostream>
#include <limits.h>
#include <vector>
#include <array>
using namespace std;
typedef long long ll;
#define SIZE 1e9
void solve() {
int s, n;
cin >> s >> n;
array<ll, (LLONG_MAX/1000)> dp;
for (int i = 0; i < n; ++i) {
int w;
ll v, q;
cin >> v >> w >> q;
// fucking binary optimization
for (ll k = 1; q > 0; k <<= 1) {
ll take = min(k, q);
ll chunkV = take * v;
ll chunkW = take * w;
if (chunkW <= s) {
for (int j = s; j >= chunkW; --j) {
dp[j] = max(dp[j], dp[j - chunkW] + chunkV);
}
}
q -= take;
}
}
cout << dp[s] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}| # | 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... | ||||
