#include <bits/stdc++.h>
using namespace std;
#define name "IO"
#define int long long
const int inf = 1e9;
const int maxn = 1e7 + 5;
int n;
void solve()
{
cin >> n;
int one = 0;
vector<pair<int,int>> p;
for(int i = 1; i <= n; i++)
{
int x, y;
cin >> x >> y;
one += (y == 1);
p.push_back({x, y});
}
if(one == n)
{
cout << n << "\n";
return;
}
stack<pair<int,int>> st;
int l = p[0].first, r = p.back().first;
auto check = [&](int x, int y) -> bool{
auto [i, j] = st.top();
if(x - y <= i - j && x + y >= i + j) return 1;
return 0;
};
auto ok = [&](int x, int y) -> bool {
auto [i, j] = st.top();
if(x + y > i + j) return 1;
return 0;
};
for(int i = 0; i < p.size(); i++)
{
auto [x, y] = p[i];
while(!st.empty() && check(x, y)) st.pop();
if(st.empty() || ok(x, y)) st.push({x, y});
}
cout << st.size() << "\n";
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
int t = 1;
while(t--) solve();
std::cerr << "Time: " << clock() - start << "ms\n";
return 0;
}
# | 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... |