제출 #879461

#제출 시각아이디문제언어결과실행 시간메모리
879461TAhmed33Akcija (COCI21_akcija)C++98
40 / 110
439 ms524288 KiB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 25;
typedef long long ll;
int n; pair <ll, ll> a[MAXN];
pair <ll, ll> dp[MAXN][MAXN];
pair <ll, ll> comb (pair <ll, ll> a, pair <ll, ll> b) {
	if (a.first > b.first) return a;
	if (a.first < b.first) return b;
	return {a.first, min(a.second, b.second)};
}
vector <pair <ll, ll>> subs;
void recurse (int pos, int sze, ll cost) {
	if (pos > n) {
		subs.push_back({sze, cost});
		return;
	}
	recurse(pos + 1, sze, cost);
	if (sze + 1 <= a[pos].second) recurse(pos + 1, sze + 1, cost + a[pos].first);
}
int main () {
	cin >> n; int k; cin >> k;
	for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
	sort(a + 1, a + n + 1, [] (pair <ll, ll> &x, pair <ll, ll> &y) { return x.second < y.second; });
	if (k != 1) {
		recurse(1, 0, 0);
		sort(subs.begin(), subs.end(), [] (pair <ll, ll> &a, pair <ll, ll> &b) {
			return a.first == b.first ? a.second < b.second : a.first > b.first;
		});
		for (int i = 0; i < k; i++) {
			cout << subs[i].first << " " << subs[i].second << '\n';
		}
		return 0;
	}
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] = dp[i + 1][j];
			if (j + 1 <= a[i].second) {
				dp[i][j] = comb(dp[i][j], {dp[i + 1][j + 1].first + 1, dp[i + 1][j + 1].second + a[i].first});
			}
		}
	}
	cout << dp[1][0].first << " " << dp[1][0].second << '\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...