# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1009139 |
2024-06-27T09:19:17 Z |
lrancic |
Schools (IZhO13_school) |
C++17 |
|
141 ms |
8484 KB |
#include <iostream>
#include <vector>
#include <algorithm>
std::vector<bool> city;
int solve(int n, int m, int s, std::vector<std::pair<int, int>> &music, std::vector<std::pair<int, int>> &sports, int i = 0, int c = 0) {
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 |
1 ms |
348 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 |
348 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 |
548 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
16 ms |
1372 KB |
Output isn't correct |
14 |
Incorrect |
34 ms |
2560 KB |
Output isn't correct |
15 |
Incorrect |
67 ms |
4600 KB |
Output isn't correct |
16 |
Incorrect |
72 ms |
5192 KB |
Output isn't correct |
17 |
Incorrect |
94 ms |
6476 KB |
Output isn't correct |
18 |
Incorrect |
106 ms |
6992 KB |
Output isn't correct |
19 |
Incorrect |
126 ms |
7508 KB |
Output isn't correct |
20 |
Incorrect |
141 ms |
8484 KB |
Output isn't correct |