Submission #528377

#TimeUsernameProblemLanguageResultExecution timeMemory
528377CSQ31Akcija (COCI21_akcija)C++17
90 / 110
5047 ms31196 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define sz(a) (int)(a.size()) int n,k; vector<ll>s[2001]; vector<ll>comb(vector<ll>a,vector<ll>b,ll x){ int p = 0,q = 0; vector<ll>c; while(p != sz(a) || q != sz(b)){ if(q!=sz(b) && (p==sz(a) || a[p] > b[q]+x)){ c.push_back(b[q]+x); q++; }else{ c.push_back(a[p]); p++; } } while(sz(c) > k)c.pop_back(); return c; } int main() { cin>>n>>k; vector<array<ll,2>>v(n); s[0] = {0}; for(int i=0;i<n;i++)cin>>v[i][1]>>v[i][0]; sort(v.begin(),v.end()); for(int i=0;i<n;i++){ for(int j=n;j;j--){ if(!sz(s[j-1]))continue; if(v[i][0] >= j)s[j] = comb(s[j],s[j-1],v[i][1]); } } int cnt = 0; for(int j=n;j>=1;j--){ if(cnt==k)break; for(ll x:s[j]){ cout<<j<<" "<<x<<'\n'; cnt++; if(cnt==k)break; } } while(cnt < k){ cnt++; cout<<0<<" "<<0<<'\n'; } }
#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...