Submission #861378

#TimeUsernameProblemLanguageResultExecution timeMemory
861378anarch_yKnapsack (NOI18_knapsack)C++17
73 / 100
210 ms262144 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define all(x) begin(x), end(x) #define pb push_back #define int long long signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int S, N; cin >> S >> N; vector<int> V(N+1, 0), W(N+1, 0), K(N+1, 0); for(int i=1; i<=N; i++){ cin >> V[i] >> W[i] >> K[i]; K[i] = min(K[i], S/W[i]); } vector<vector<int>> dp(N+1, vector<int>(S+1, 0)); for(int i=1; i<=N; i++){ for(int j=1; j<=S; j++){ dp[i][j] = dp[i-1][j]; for(int k=1; k<=K[i]; k++){ int w = k*W[i]; if(j>=w){ dp[i][j] = max(dp[i][j], dp[i-1][j-w]+k*V[i]); } } } } cout << dp[N][S]; }
#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...