제출 #1089995

#제출 시각아이디문제언어결과실행 시간메모리
1089995EmmaXIIKnapsack (NOI18_knapsack)C++17
73 / 100
1051 ms3676 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; using vi = vector<int>; using vvi = vector<vector<int>>; using vll = vector<ll>; using vvll = vector<vector<ll>>; #define all(x) x.begin(), x.end() #define ckmin(a,b) a = min(a,b) #define ckmax(a,b) a = max(a,b) int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); int N, S; cin >> S >> N; vll V(N); vi W(N); vll K(N); for (int i=0;i<N;i++) cin >> V[i] >> W[i] >> K[i]; vll dp(S+1, 0); for (int i=0;i<N;i++) { vll ndp(S+1, 0); for (int j=0;j<=S;j++) { for (int k=0;j+k*W[i]<=S && k <= K[i];k++) { ckmax(ndp[j+k*W[i]], dp[j] + k * V[i]); } } swap(dp, ndp); } cout << dp[S] << endl; return 0; }
#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...