| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1364933 | shreyas_arun | Knapsack (NOI18_knapsack) | C++20 | 681 ms | 452 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
ll s, n;
cin >> s >> n;
vector<ll> dp(s + 1, 0);
for (int i = 0; i < n; i++)
{
ll val, w, k;
cin >> val >> w >> k;
if (w * k >= s)
{
for (int j = w; j <= s; j++)
{
dp[j] = max(dp[j], dp[j - w] + val);
}
}
else
{
ll cnt = 1;
while (k > 0)
{
ll take = min(cnt, k);
ll weight = w * take;
ll value = val * take;
for (int j = s; j >= weight; j--)
{
dp[j] = max(dp[j], dp[j - weight] + value);
}
cnt *= 2;
k -= take;
}
}
}
cout << dp[s] << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
