#include <iostream>
using namespace std;
using ll = long long;
const int BUF_SZ = 1 << 15;
inline namespace Input {
char buf[BUF_SZ];
int pos;
int len;
char next_char() {
if (pos == len) {
pos = 0;
len = (int)fread(buf, 1, BUF_SZ, stdin);
if (!len) { return EOF; }
}
return buf[pos++];
}
int read_int() {
int x;
char ch;
int sgn = 1;
while (!isdigit(ch = next_char())) {
if (ch == '-') { sgn *= -1; }
}
x = ch - '0';
while (isdigit(ch = next_char())) { x = x * 10 + (ch - '0'); }
return x * sgn;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, ans = 0, x, y; n = read_int(); if (n == 1) { cout << 1; return 0; }
int a[n], b[n], maxal[n], minbr[n];
for (int i = 0; i < n; i++) { x = read_int(); y = read_int(); a[i] = x + y, b[i] = x - y; }
maxal[0] = a[0]; for (int i = 1; i < n; i++) maxal[i] = max(maxal[i - 1], a[i]);
minbr[n - 1] = b[n - 1]; for (int i = n - 2; i >= 0; i--) minbr[i] = min(minbr[i + 1], b[i]);
ans += (b[0] < minbr[1]) + (a[n - 1] > maxal[n - 2]);
for (int i = 1; i < n - 1; i++) ans += (b[i] < minbr[i + 1] && a[i] > maxal[i - 1]);
cout << ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |