Submission #797866

#TimeUsernameProblemLanguageResultExecution timeMemory
797866OrazBKnapsack (NOI18_knapsack)C++14
17 / 100
1 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; for (int j = S-w; j >= 0; j--){ if (!j or dp[j]) dp[j+w] = max(dp[j+w], dp[j]+v); } // for (int j = 0; j <= S-w; j++){ // if ((!j or dp[j]) and cur[j] < k and dp[j+w] < dp[j]+v){ // dp[j+w] = dp[j]+v; // 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...