This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |