Submission #446081

#TimeUsernameProblemLanguageResultExecution timeMemory
446081PulgsterKnapsack (NOI18_knapsack)C++17
100 / 100
71 ms3652 KiB
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; typedef long long ll; using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { // #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } // sim dor(const c&) { ris; } }; #ifdef ASJKD } #endif #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define read(x) for(auto &i : (x)){cin>>i;} #define all(x) begin(x), end(x) #define pb push_back #define pll pair<ll,ll> #define pii pair<int,int> // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> int mod = 1e9+7; int INF = 1e9+1e8; ll INF64 = 1e18; ll binpow(ll a, ll b, ll mod){ ll res = 1; while(b > 0){ if(b % 2){ res = res * a % mod; } a = a * a % mod; b >>= 1; } return res; } void mxself(int &a, int b){ a = max(a, b); } void rpii(pii &a){ cin>>a.first>>a.second; } void mnself(int &a,int b){ a = min(a, b); } void mult(ll &a, ll b){ a = a * b % mod; } void add(ll &a, ll b){ a = (a + b); while(a >= mod) a -= mod; } const int mx5 = 200*32; void test_case(int test){ int s, n; cin>>s>>n; vector<vector<pii>> a(2002); for(int i=0;i<n;i++){ int v,w,q; cin>>v>>w>>q; a[w].pb({v, q}); } vector<ll> dp(2002); for(int cur=1;cur<=s;cur++){ sort(all(a[cur])); for(int rep=0;rep<s/cur;rep++){ // debug() << imie(a[cur]); if(a[cur].empty()) break; if(a[cur].back().second == 0) a[cur].pop_back(); if(a[cur].empty()) break; ll me = a[cur].back().first; a[cur][a[cur].size()-1].second--; for(int i=s;i>=0;i--){ if(i-cur >= 0){ dp[i] = max(dp[i], dp[i-cur] + me); } else{ break; } } } } ll best = 0; for(int i=0;i<=s;i++){ best = max(best, dp[i]); } cout<<best<<'\n'; } int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int t=1; // setIO("feast"); // cin>>t; for(int test=1;test<=t;test++){ test_case(test); } 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...