#include <iostream>
#include <vector>
#include <algorithm>
int readInt() {
bool minus = false;
int result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus = true; else result = ch - '0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result * 10 + (ch - '0');
}
if (minus)
return -result;
else
return result;
}
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);
// std::cout << std::endl;
// for (size_t i = 0; i < gyms.size(); ++i) {
// std::cout << i << ": " << gyms[i].xp << ", " << gyms[i].maxLevel << std::endl;
// }
// return simulate(gyms);
//}
void make_ordered() {
int n; std::cin >> n;
std::vector<int> gymXP(n, 0);
std::vector<int> gymMaxes(n, 0);
for (int& i : gymXP) { i = readInt(); }
for (int& i : gymMaxes) { i = readInt(); }
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);
std::cout << std::endl;
for (size_t i = 0; i < gyms.size(); ++i) {
std::cout << i << ": " << gyms[i].xp << ", " << gyms[i].maxLevel << std::endl;
}
return simulate(gyms);
}
int main() {
make_ordered();
}
Compilation message
Main.cpp: In function 'void make_ordered()':
Main.cpp:101:23: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
101 | for (size_t i = 0; i < n; ++i) {
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
735 ms |
26024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |