# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647154 | Alma | Akcija (COCI21_akcija) | C++14 | 751 ms | 524288 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>
using namespace std;
#define fi first
#define se second
using ll = long long;
using ii = pair<int,int>;
const int INF = 1e9;
const ll LLINF = 1e18;
using vi = vector<int>;
using vvi = vector<vi>;
void setIO (string fileName) {
ios::sync_with_stdio(false);
cin.tie(NULL);
if (fileName != "std") {
freopen((fileName + ".in").c_str(), "r", stdin);
freopen((fileName + ".out").c_str(), "w", stdout);
}
}
int n, k;
vector<ii> ans, gifts;
// bool comp(ii& a, ii& b) {
// if (a.fi == b.fi) return a.se < b.se;
// return a.fi > b.fi;
// }
void bt (int i, int cnt, int val) {
if (i == n) {
// cerr << cnt << ' ' << val << '\n';
ans.push_back({-cnt, val});
return;
}
// cerr << i << ' ' << cnt << '\n';
bt(i+1, cnt, val);
if (gifts[i].fi <= cnt) return;
bt(i+1, cnt+1, val+gifts[i].se);
}
int main() {
setIO("std");
cin >> n >> k;
gifts = vector<ii>(n);
for (ii& par: gifts) cin >> par.se >> par.fi;
sort(gifts.begin(), gifts.end());
bt(0, 0, 0);
sort(ans.begin(), ans.end());
for (int i = 0; k > 0 and i < (int)ans.size(); i++, k--) {
cout << -ans[i].fi << ' ' << ans[i].se << '\n';
}
while (k > 0) {
cout << "0 0\n";
k--;
}
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... |