Submission #445812

#TimeUsernameProblemLanguageResultExecution timeMemory
445812PulgsterKnapsack (NOI18_knapsack)C++17
29 / 100
3 ms332 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; } void test_case(int test){ int s, n; cin>>s>>n; vector<ll> v(n); vector<ll> w(n); vector<ll> q(n); for(int i=0;i<n;i++){ cin>>v[i]>>w[i]>>q[i]; } vector<ll> dp(s+1); for(int rep=0;rep<n;rep++){ vector<int> mx(s+1); vector<ll> nw(s+1); for(int i=0;i<=s;i++){ if(i < w[rep]){ mx[i] = i; nw[i]=dp[i]; } else{ ll last = mx[i-w[rep]]; // debug() << imie((i - last)); ll h = min(q[rep], (i - last) / w[rep]); while((i-last)/w[rep] > q[rep]){ mx[i-w[rep]] += w[rep]; last += w[rep]; } last = mx[i-w[rep]]; // debug() << imie(h); if(h * v[rep] + dp[last] < dp[i]){ mx[i] = i; nw[i] = dp[i]; } else{ mx[i] = mx[i-w[rep]]; nw[i] = dp[last] + h * v[rep]; } } } for(int i=1;i<=s;i++){ dp[i] = max(dp[i], nw[i]); dp[i] = max(dp[i], dp[i-1]); } } ll ans = 0; for(int i=s;i>=0;i--){ ans = max(ans, dp[i]); } cout<<ans<<'\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...