Submission #1009194

# Submission time Handle Problem Language Result Execution time Memory
1009194 2024-06-27T09:53:11 Z lrancic Schools (IZhO13_school) C++17
15 / 100
136 ms 7160 KB
#include <iostream>
#include <vector>
#include <algorithm>

std::vector<bool> city;

long long solve(int n, int m, int s, std::vector<std::pair<int, int>> &music, std::vector<std::pair<int, int>> &sports, int i = 0, long long c = 0LL) {
	if (i >= n) return c;

	for (; i < n; i++) {
		if (music[i].second == sports[i].second && m > 0 && s > 0) {
			city[music[i].second] = true;
			return std::max(solve(n, m-1, s, music, sports, i+1, c+music[i].first), solve(n, m, s-1, music, sports, i+1, c+sports[i].first));
		}

		if (m > 0 && !city[music[i].second]) { c += music[i].first; m--; city[music[i].second] = true; }
		if (s > 0 && !city[sports[i].second]) { c += sports[i].first; s--; city[sports[i].second] = true; }

		if (m < 1 && s < 1) return c;
	}

	return c;
}

int main() {
	int n, m, s; std::cin >> n >> m >> s;
	std::vector<std::pair<int, int>> music(n), sports(n);
	for (int i = 0; i < n; i++) { std::cin >> music[i].first >> sports[i].first; music[i].second = sports[i].second = i; city.push_back(false); }

	// for (std::pair<int, int> i : music) std::cout << i.first << ' ' << i.second << '\t';
	// std::cout << '\n'; 
	// for (std::pair<int, int> i : sports) std::cout << i.first << ' ' << i.second << '\t';
	// std::cout << '\n'; 

	std::sort(sports.begin(), sports.end(), std::greater<std::pair<int, int>>()); std::sort(music.begin(), music.end(), std::greater<std::pair<int, int>>());
	std::cout << solve(n, m, s, music, sports) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 2 ms 348 KB Output isn't correct
8 Incorrect 2 ms 344 KB Output isn't correct
9 Incorrect 2 ms 344 KB Output isn't correct
10 Incorrect 3 ms 348 KB Output isn't correct
11 Incorrect 2 ms 348 KB Output isn't correct
12 Incorrect 2 ms 348 KB Output isn't correct
13 Incorrect 15 ms 1372 KB Output isn't correct
14 Incorrect 32 ms 2396 KB Output isn't correct
15 Incorrect 71 ms 3936 KB Output isn't correct
16 Incorrect 76 ms 4568 KB Output isn't correct
17 Incorrect 93 ms 5200 KB Output isn't correct
18 Incorrect 107 ms 5804 KB Output isn't correct
19 Incorrect 119 ms 6484 KB Output isn't correct
20 Incorrect 136 ms 7160 KB Output isn't correct