Submission #1308257

#TimeUsernameProblemLanguageResultExecution timeMemory
1308257tolgaKnapsack (NOI18_knapsack)C++20
17 / 100
1095 ms580 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' int main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int s, n; cin >> s >> n; vector<ll> p(n), w(n), cnt(n); int prev = 1; for (ll i = 0; i < n; i++) { int x; cin >> p[i] >> w[i] >> x; cnt[i] = x - prev + 1; prev = x; } const ll INF = 1e9; vector<ll> dp(s + 1); ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < cnt[i]; j++) for (int weight = s; weight >= w[i]; weight--) { if (dp[weight] < dp[weight - w[i]] + p[i]) { dp[weight] = dp[weight - w[i]] + p[i]; ans = max(ans, dp[weight]); } } 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...