제출 #861329

#제출 시각아이디문제언어결과실행 시간메모리
861329anarch_yKnapsack (NOI18_knapsack)C++17
73 / 100
222 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]); } int dp[N+1][S+1] = {}; 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...