This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
bool eats(std::pair<int, int> eater, std::pair<int, int> eaten) {
int dist = std::abs(eater.first - eaten.first);
return dist <= eater.second - eaten.second;
}
int main() {
std::cin.tie(NULL);
std::iostream::sync_with_stdio(false);
int N;
std::cin >> N;
std::vector<std::pair<int, int>> input(N);
for (int i = 0; i < N; i++) {
int X, E;
std::cin >> X >> E;
input[i] = {X - E, X + E};
}
std::sort(input.begin(), input.end(), [](const std::pair<int, int> a,
const std::pair<int, int> b) {
return a.first < b.first || (a.first == b.first && a.second > b.second);
});
const int INF = 1000000000;
std::pair<int, int> last = {-INF - 1, -INF - 1};
int res = 0;
for (int i = 0; i < input.size(); i++) {
auto [L, R] = input[i];
// otherwise this is eaten
if (R > last.second) {
res++;
last = {L, R};
}
}
std::cout << res;
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < input.size(); i++) {
| ~~^~~~~~~~~~~~~~
Main.cpp:34:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | auto [L, R] = input[i];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |