Submission #1007673

#TimeUsernameProblemLanguageResultExecution timeMemory
1007673MuhammetKnapsack (NOI18_knapsack)C++17
37 / 100
1018 ms73756 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]; 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 j = 1; j <= k[i]; j++){ v1.push_back({v[i],w[i]}); } } for(auto j : v1){ ll va = j.ff, we = j.ss; for(int i = s; i >= 0; i--){ if(dp[i] != 0 or i == 0){ dp[i + we] = max(dp[i + we], dp[i] + va); } } } ll ans = 0; for(int i = 0; i <= s; i++){ ans = max(dp[i], ans); } 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...