제출 #508742

#제출 시각아이디문제언어결과실행 시간메모리
508742bshenKnapsack (NOI18_knapsack)C++17
73 / 100
258 ms1876 KiB
#include <iostream> #include <vector> using namespace std; long long s, n, v[100001], w[10001], k[100001]; long long best=0; long long dp[2001]; int main() { cin >> s >> n; for (int i=0; i<n; i++) { cin >> v[i] >> w[i] >> k[i]; k[i] = min(k[i], s/w[i]); } for (int i=0; i<n; i++) { for (int j=0; j<k[i]; j++) { for (int we=s; we>=0; we--) { if (we-w[i] >=0) dp[we] = max(dp[we], dp[we-w[i]] + 1ll*v[i]); best = max(best, dp[we]); } } } cout << best << endl; }
#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...