Submission #785935

#TimeUsernameProblemLanguageResultExecution timeMemory
785935rainyhawkKnapsack (NOI18_knapsack)C++17
73 / 100
147 ms262144 KiB
#include <iostream> #include <algorithm> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); long long s, n, ans = 0; cin >> s >> n; long long v[n], w[n], k[n]; long long dp[n+1][s+1]; for(long long i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i]; for(long long i = 0; i <= n; i++){ for(long long j = 0; j<= s; j++){ dp[i][j] = -1; } } dp[0][0] = 0; for(long long i = 0; i < n; i++){ for(long long j = 0; j<= s; j++){ if (dp[i][j] == -1) continue; for(long long l = 0; l <= k[i]; l++){ if (j+l*w[i] > s) break; dp[i+1][j+l*w[i]] = max(dp[i+1][j+l*w[i]], dp[i][j] + l*v[i]); ans = max (ans, dp[i+1][j+l*w[i]]); } } } cout << ans << 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...