# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1188451 | teokakabadze | Knapsack (NOI18_knapsack) | C++20 | 1097 ms | 444 KiB |
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define int long long
#define pii pair<int, int>
using namespace std;
const int N = 5e5 + 5, M = 1e9 + 7;
int T, n, s, dp[2003];
main()
{
std::ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> n;
for(int i = 0; i < n; i++)
{
int v, w, k;
cin >> v >> w >> k;
for (int st = 0; st < w; st++)
{
deque<pii> d;
for(int ind = st; ind <= s; ind += w)
{
int val = dp[ind] - (ind / w) * v;
while(!d.empty() && d.back().f <= val)
d.pop_back();
d.pb({val, ind / w});
while(!d.empty() && d.front().s < (ind / w) - k)
d.pop_front();
dp[ind] = d.front().f + (ind / w) * v;
}
}
}
cout << dp[s] << '\n';
}
Compilation message (stderr)
# | 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... |