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>
using namespace std;
const int MX=10000005;
int n,a[MX],b[MX],pre[MX],pos[MX];
stack<int> st;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n;
for (int i=1; i<=n; ++i) {
int x,y;
cin>>x>>y;
a[i]=x-y;
b[i]=x+y;
}
for (int i=1; i<=n; ++i) {
int idx=i-1;
while (a[i]<=a[idx] && idx>=1) idx=pre[idx];
pre[i]=idx;
}
for (int i=n; i>=1; --i) {
int idx=i+1;
while (b[i]>=b[idx] && idx<=n) idx=pos[idx];
pos[i]=idx;
}
st.push(1);
for (int i=2; i<=n; ++i) {
//consider point i
int k=st.top();
if (pos[k]<=i) {
//push rod at point i
while (!st.empty() && pre[i]<=pre[st.top()]) st.pop();
st.push(i);
}
}
cout<<st.size();
}
# | 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... |