Submission #543717

#TimeUsernameProblemLanguageResultExecution timeMemory
543717zammyKnapsack (NOI18_knapsack)C++17
73 / 100
212 ms262144 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int inf = INT_MAX, mod = 1e9 + 7, MAX_N = (1e5), MAX_S = 2000; int dp[MAX_N + 1][MAX_S + 1]; void solve() { int S, N; cin >> S >> N; vector<int> V(N + 1), W(N + 1), K(N + 1); for (int i = 1; i <= N; i++) cin >> V[i] >> W[i] >> K[i]; 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 wt = W[i] * k; if (j - wt < 0) break; dp[i][j] = max(dp[i][j], (V[i] * k) + dp[i - 1][j - wt]); } } } cout << dp[N][S] << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed; cout << setprecision(9); int tt = 1; // cin >> tt; for (int i = 1; i <= tt; i++) { // cout << "Case #" << i << ": "; solve(); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << 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...