Submission #1008314

#TimeUsernameProblemLanguageResultExecution timeMemory
1008314MuhammetKnapsack (NOI18_knapsack)C++17
12 / 100
1 ms6492 KiB
#include <bits/stdc++.h> using namespace std; #define N 300005 #define ll long long int #define sz(x) (int)x.size() #define ff first #define ss second ll T, n, s, v[N], w[N], k[N], dp[N], a[N]; vector <pair<ll,ll>> v1; int main(){ cin >> s >> n; for(int i = 1; i <= n; i++){ cin >> v[i] >> w[i] >> k[i]; } for(int i = 1; i <= n; i++){ for(int j = 0; j <= s; j++){ if(dp[j] != 0 or j == 0){ if(a[j] + 1 <= k[i]){ if(dp[j] + v[i] > dp[j + w[i]]){ dp[j + w[i]] = (dp[j] + v[i]); a[j + w[i]] = a[j] + 1; } } } } for(int j = 0; j <= s; j++) a[j] = 0; } ll ans = 0; for(int i = 0; i <= s; i++){ ans = max(ans,dp[i]); } cout << ans; return 0; }
#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...