Submission #797876

#TimeUsernameProblemLanguageResultExecution timeMemory
797876OrazBKnapsack (NOI18_knapsack)C++14
73 / 100
1070 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <int, int> #define pb push_back #define ff first #define ss second const int N = 1e5+5; int dp[N], cur[N]; int main () { ios::sync_with_stdio(false); cin.tie(0); int S, n; cin >> S >> n; for (int i = 1; i <= n; i++){ int v, w, k; cin >> v >> w >> k; k = min(k, S); while(k--){ for (int j = S-w; j >= 0; j--){ if (!j or dp[j]) dp[j+w] = max(dp[j+w], dp[j]+v); } } // wh // for (int j = 0; j <= S-w; j++){ // if ((!j or dp[j]) and cur[j] < k){ // if (dp[j+w] < dp[j]+v){ // dp[j+w] = dp[j]+v; // cur[j+w] = cur[j]+1; // }else if (dp[j+w] == dp[j]+v) cur[j+w] = min(cur[j+w], cur[j]+1); // } // } // for (int j = 0; j <= S; j++) cur[j] = 0; } cout << *max_element(dp+1,dp+S+1); }
#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...