# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
902618 | SalihSahin | Akcija (COCI21_akcija) | C++17 | 5010 ms | 18756 KiB |
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>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e17*2;
const int N = 2e5 + 5;
int32_t main(){
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
int n, k;
cin>>n>>k;
multiset<int> best[n+2];
best[0].insert(0);
vector<pair<int, int> > a(n);
for(int i = 0; i < n; i++){
cin>>a[i].second>>a[i].first;
}
sort(a.begin(), a.end());
for(int i = 0; i < n; i++){
for(int j = a[i].first-1; j >= 0; j--){
for(auto itr: best[j]){
best[j+1].insert(a[i].second + itr);
}
while(best[j+1].size() > k){
auto k = best[j+1].end();
k--;
best[j+1].erase(k);
}
}
}
vector<pair<int, int> > ans;
for(int i = n; i >= 0; i--){
for(auto itr: best[i]){
ans.pb(mp(i, itr));
}
if(ans.size() > k) break;
}
for(int i = 0; i < k; i++){
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}
return 0;
}
Compilation message (stderr)
# | 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... |