Submission #965305

#TimeUsernameProblemLanguageResultExecution timeMemory
965305UnforgettableplKnapsack (NOI18_knapsack)C++17
73 / 100
1062 ms7256 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(2000,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 >= wt; i--) { DP[i] = max(DP[i],DP[i-wt]+val); } } } cout << DP[W]; }
#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...