Submission #965308

#TimeUsernameProblemLanguageResultExecution timeMemory
965308UnforgettableplKnapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define f first
#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;
const ll modulo = 1e4;
//#define int ll
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.in","r",stdin);
//    freopen("haybales.out","w",stdout);
    int W,n;
    cin >> W >> n;
    if(n==1){
        int v,w,k;
        cin >> v >> w >> k;
        assert(n==1);
        cout << v*min(k,W/w);
        return 0;
    }
    vector<tuple<ll,ll,ll>> items(n);
    for (int i = 0; i < n; i++) {
        int a,b,c;
        cin >> a >> b >> c;
        c=min(s/b,c);
        items.emplace_back(a,b,c);
    }
    vector<ll> DP(W+1);
    for(auto[val,wt,k]:items){
        for(int x=1;x<=k;x++){
            for (int i = W; i >= x*wt; i--) {
                DP[i] = max(DP[i],DP[i-wt]+val);
            }
        }
    }
    cout << DP[W];
}

Compilation message (stderr)

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:13:11: error: 'second' was not declared in this scope
   13 | #define s second
      |           ^~~~~~
knapsack.cpp:37:15: note: in expansion of macro 's'
   37 |         c=min(s/b,c);
      |               ^