#include <iostream>
#include <vector>
#include <algorithm>
struct gymPair {
gymPair(int a, int b) {
xp = a;
maxLevel = b;
}
int xp;
int maxLevel;
};
bool compare_gyms(const gymPair& a, const gymPair& b) {
int asum{ a.maxLevel + a.xp };
int bsum{ b.maxLevel + b.xp };
if (asum != bsum) {
return (asum < bsum);
}
else {
if (a.maxLevel != b.maxLevel) {
return (a.maxLevel < b.maxLevel);
}
else {
if (a.xp != b.xp) {
return (a.xp < b.xp);
}
}
}
return true;
}
void simulate(std::vector<gymPair> gyms) {
int xp{ 0 };
int badges{ 0 };
for (const gymPair& gym : gyms) {
if (xp > gym.maxLevel) { continue; }
else {
xp += gym.xp;
++badges;
}
}
std::cout << badges;
}
void make_ordered() {
std::ios_base::sync_with_stdio(false);
int n; std::cin >> n;
std::vector<int> gymXP(n, 0);
std::vector<int> gymMaxes(n, 0);
for (int& i : gymXP) { std::cin >> i; }
for (int& i : gymMaxes) { std::cin >> i; }
std::vector<gymPair> gyms;
for (size_t i = 0; i < n; ++i) {
if (gymXP[i] == gymMaxes[i]) { continue; }
gyms.push_back(gymPair(gymXP[i], gymMaxes[i]));
}
std::sort(gyms.begin(), gyms.end(), compare_gyms);
return simulate(gyms);
}
int main() {
make_ordered();
}
Compilation message
Main.cpp: In function 'void make_ordered()':
Main.cpp:57:23: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
57 | for (size_t i = 0; i < n; ++i) {
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
21360 KB |
Output is correct |
2 |
Correct |
140 ms |
21700 KB |
Output is correct |
3 |
Correct |
141 ms |
21444 KB |
Output is correct |
4 |
Correct |
155 ms |
21616 KB |
Output is correct |
5 |
Correct |
143 ms |
21504 KB |
Output is correct |
6 |
Correct |
139 ms |
20528 KB |
Output is correct |
7 |
Correct |
138 ms |
19920 KB |
Output is correct |
8 |
Correct |
142 ms |
20464 KB |
Output is correct |
9 |
Correct |
139 ms |
20412 KB |
Output is correct |
10 |
Correct |
136 ms |
20420 KB |
Output is correct |
11 |
Runtime error |
87 ms |
24004 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
146 ms |
21360 KB |
Output is correct |
22 |
Correct |
140 ms |
21700 KB |
Output is correct |
23 |
Correct |
141 ms |
21444 KB |
Output is correct |
24 |
Correct |
155 ms |
21616 KB |
Output is correct |
25 |
Correct |
143 ms |
21504 KB |
Output is correct |
26 |
Correct |
139 ms |
20528 KB |
Output is correct |
27 |
Correct |
138 ms |
19920 KB |
Output is correct |
28 |
Correct |
142 ms |
20464 KB |
Output is correct |
29 |
Correct |
139 ms |
20412 KB |
Output is correct |
30 |
Correct |
136 ms |
20420 KB |
Output is correct |
31 |
Runtime error |
87 ms |
24004 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |