제출 #595343

#제출 시각아이디문제언어결과실행 시간메모리
595343yaroslav06Knapsack (NOI18_knapsack)C++14
73 / 100
1058 ms2676 KiB
#include <iostream> const int N = 2001; using namespace std; typedef long long ll; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll dp[N][2]{}; int s, n, v[(int) 1e5], w[(int) 1e5], k[(int) 1e5]; cin >> s >> n; for(int i = 0; i < n; ++i) cin >> v[i] >> w[i] >> k[i]; for(int i = 0; i < n; ++i){ for(int j = 1; j <= k[i] && j * w[i] <= s; ++j) for(int t = 1; t <= s; ++t) if(t - j * w[i] >= 0) dp[t][1] = max(dp[t][1], dp[t - j * w[i]][0] + j * v[i]); for(int j = 0; j <= s; ++j) dp[j][0] = dp[j][1]; } cout << dp[s][0] << '\n'; }
#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...