Submission #1319309

#TimeUsernameProblemLanguageResultExecution timeMemory
1319309aslayeryl81Knapsack (NOI18_knapsack)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int s, n;
    cin >> s >> n;
    vector<int> dp(s + 1, 0);
    for(int i = 0; i < n; i++) 
    {
        int v, w, k;
        cin >> v >> w >> k;
        int maxx = min((s / w), k);
        for(int p = 1; maxx > 0; p <<= 1) 
        {
            int dem = min(p, maxx);
            maxx -= dem;
            int W = dem * W;
            int val  = dem * V;
            for(int w = s; w >= W; w--)
                dp[w] = max(dp[w], dp[w - W] + val);
        }
    }
    cout << *max_element(dp.begin(), dp.end());
    return 0;
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:22:30: error: 'V' was not declared in this scope
   22 |             int val  = dem * V;
      |                              ^