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 main()
{
int n,k;
cin>>n>>k;
vector<array<ll,2>>v(n);
for(int i=0;i<n;i++)cin>>v[i][1]>>v[i][0];
sort(v.begin(),v.end());
multiset<pair<ll,ll>>s;
for(int i=0;i<n;i++){
vector<pair<ll,ll>>tmp;
for(auto x:s){
if(v[i][0] >= -x.first + 1)tmp.push_back({x.first-1,x.second + v[i][1]});
}
tmp.push_back({-1,v[i][1]});
for(auto x:tmp)s.insert(x);
while(sz(s) > k){
auto it = s.end();
it--;
s.erase(it);
}
}
if(sz(s)<k)s.insert({0,0});
for(auto x:s)cout<<-x.first<<" "<<x.second<<'\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... |