Submission #1188451

#TimeUsernameProblemLanguageResultExecution timeMemory
1188451teokakabadzeKnapsack (NOI18_knapsack)C++20
73 / 100
1097 ms444 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)

knapsack.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...