Submission #879461

# Submission time Handle Problem Language Result Execution time Memory
879461 2023-11-27T13:35:51 Z TAhmed33 Akcija (COCI21_akcija) C++
40 / 110
439 ms 524288 KB
#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 time Memory Grader output
1 Correct 19 ms 61108 KB Output is correct
2 Correct 12 ms 63832 KB Output is correct
3 Correct 11 ms 58968 KB Output is correct
4 Correct 11 ms 57988 KB Output is correct
5 Correct 12 ms 63068 KB Output is correct
6 Correct 10 ms 57692 KB Output is correct
7 Correct 10 ms 63324 KB Output is correct
8 Correct 10 ms 58968 KB Output is correct
9 Correct 10 ms 57436 KB Output is correct
10 Correct 12 ms 59740 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 61108 KB Output is correct
2 Correct 12 ms 63832 KB Output is correct
3 Correct 11 ms 58968 KB Output is correct
4 Correct 11 ms 57988 KB Output is correct
5 Correct 12 ms 63068 KB Output is correct
6 Correct 10 ms 57692 KB Output is correct
7 Correct 10 ms 63324 KB Output is correct
8 Correct 10 ms 58968 KB Output is correct
9 Correct 10 ms 57436 KB Output is correct
10 Correct 12 ms 59740 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 13 ms 61148 KB Output is correct
15 Correct 13 ms 63836 KB Output is correct
16 Correct 11 ms 58716 KB Output is correct
17 Correct 14 ms 57752 KB Output is correct
18 Correct 12 ms 63068 KB Output is correct
19 Correct 9 ms 57692 KB Output is correct
20 Correct 11 ms 63324 KB Output is correct
21 Correct 12 ms 58716 KB Output is correct
22 Correct 10 ms 57436 KB Output is correct
23 Correct 11 ms 59740 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 439 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 9928 KB Output is correct
2 Correct 95 ms 17088 KB Output is correct
3 Correct 25 ms 6088 KB Output is correct
4 Correct 12 ms 2512 KB Output is correct
5 Correct 82 ms 17604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 984 KB Output is correct
8 Correct 1 ms 656 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 22 ms 4552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 346 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 61108 KB Output is correct
2 Correct 12 ms 63832 KB Output is correct
3 Correct 11 ms 58968 KB Output is correct
4 Correct 11 ms 57988 KB Output is correct
5 Correct 12 ms 63068 KB Output is correct
6 Correct 10 ms 57692 KB Output is correct
7 Correct 10 ms 63324 KB Output is correct
8 Correct 10 ms 58968 KB Output is correct
9 Correct 10 ms 57436 KB Output is correct
10 Correct 12 ms 59740 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 13 ms 61148 KB Output is correct
15 Correct 13 ms 63836 KB Output is correct
16 Correct 11 ms 58716 KB Output is correct
17 Correct 14 ms 57752 KB Output is correct
18 Correct 12 ms 63068 KB Output is correct
19 Correct 9 ms 57692 KB Output is correct
20 Correct 11 ms 63324 KB Output is correct
21 Correct 12 ms 58716 KB Output is correct
22 Correct 10 ms 57436 KB Output is correct
23 Correct 11 ms 59740 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Runtime error 439 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -