Submission #524032

#TimeUsernameProblemLanguageResultExecution timeMemory
524032shubham20_03Knapsack (NOI18_knapsack)C++17
12 / 100
1093 ms312 KiB
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); #define deb(x) cout<<#x<<'='<<x<<'\n'; #define deb2(x,y) cout<<#x<<'='<<x<<", "<<#y<<'='<<y<<'\n'; #define int long long #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define pb push_back #define f first #define s second #define sz(x) (int)(x).size() const long double PI = acos(-1); const int mod = 1e9 + 7, inf = 1e16; const int D = 2e5 + 10; struct det { int w, v, k; }; int knapsack(det a[], int n, int S) { if (S == 0 or n == 0) return 0; int ans = knapsack(a, n - 1, S); if (a[n - 1].w <= S and a[n - 1].k > 0) { a[n - 1].k--; ans = max(ans, a[n - 1].v + knapsack(a, n, S - a[n - 1].w)); a[n - 1].k++; } return ans; } signed main() { fastio // freopen("../input1.txt", "r", stdin); // freopen("../output1.txt", "w", stdout); int S, n; cin >> S >> n; det a[n]; for (int i = 0; i < n; i++) cin >> a[i].v >> a[i].w >> a[i].k; cout << knapsack(a, n, S) << '\n'; 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...