Submission #536620

#TimeUsernameProblemLanguageResultExecution timeMemory
536620inksamuraiAkcija (COCI21_akcija)C++17
90 / 110
5048 ms26904 KiB
#include <bits/stdc++.h> #define int ll using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define rng(i,x,n) for(int i=x;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3HspL4A ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair<int,int>; using vi=vec(int); void print(){cout<<"\n";} template<class T,class...E> void print(const T&v,const E&...u){cout<<v<<' ',print(u...);} // e #define all(a) a.begin(),a.end() using vp=vec(pii); signed main(){ _3HspL4A; int n,k; cin>>n>>k; vp a(n); rep(i,n){ cin>>a[i].se>>a[i].fi; } sort(all(a)); vec(vi) dp(n+1),nedp; dp[0]={0}; rep(i,n){ nedp=dp; auto [d,w]=a[i]; rep(j,d){ if(!sz(dp[j])) continue; for(auto s:dp[j]){ nedp[j+1].pb(s+w); } } rep(j,n+1){ sort(all(nedp[j])); while(sz(nedp[j])>k){ nedp[j].pop_back(); } } swap(dp,nedp); } vp pns; for(int j=n;j>=1;j--){ reverse(all(dp[j])); while(min(k,sz(dp[j]))){ pns.pb({j,dp[j].back()}); dp[j].pop_back(); k-=1; } } while(k){ pns.pb({0,0}); k-=1; } for(auto p:pns){ print(p.fi,p.se); } // 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...
#Verdict Execution timeMemoryGrader output
Fetching results...