Submission #1018385

#TimeUsernameProblemLanguageResultExecution timeMemory
1018385OwstinKnapsack (NOI18_knapsack)C++14
73 / 100
888 ms262144 KiB
#include <bits/stdc++.h> #include <cstdio> #include <ext/pb_ds/assoc_container.hpp> #define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0) #define pb push_back #define all(x) begin(x), end(x) #define umap unordered_map #define space " " #define TEST_CASES int a; cin >> a; for (int i = 0; i < a; i++) {solve(); cout << endl;} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct cow{ ll l, r, w; }; void solve() { int b, c; cin >> b >> c; vector<cow> vec(c); for (int i = 0; i < c; i++){ cin >> vec[i].l >> vec[i].r >> vec[i].w; } vector<ll> dp(b + 1, -1); dp[0] = 0; map<int, vector<int>> curr; curr[0] = vector<int>(c, 0); ll res = 0; for (int i = 1; i <= b; i++){ ll mx = -1; int ind = -1; for (int j = 0; j < c; j++){ if (i - vec[j].r >= 0 && dp[i - vec[j].r] != -1 && curr[i - vec[j].r][j] < vec[j].w && dp[i - vec[j].r] + vec[j].l > mx){ mx = dp[i - vec[j].r] + vec[j].l; ind = j; } } if (ind != -1) { dp[i] = mx; curr[i] = curr[i - vec[ind].r]; curr[i][ind]++; res = max(res, dp[i]); } } cout << res; } int main() { FAST_IO; //freopen("248.in", "r", stdin); //freopen("248.out", "w", stdout); //TEST_CASES; solve(); cout << endl; /*int a; cin >> a; for (int i = 1; i <= a; i++){ cout << "Case #" << i << ": "; solve(); }*/ }
#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...