# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
681793 | kthng | Untitled (POI11_tem) | C11 | 0 ms | 0 KiB |
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<iostream>
#include<deque>
using namespace std;
int a[1000000][2], n;
deque<int> dq;
int main() {
scanf("%d", &n);
int ret = 1;
for (int i = 0; i < n; i++) scanf("%d%d", &a[i][0], &a[i][1]);
for (int i = 0; i < n; i++) {
if (i && a[i - 1][0] > a[i][1]) dq.clear();
if (!dq.empty() && a[i][1] < a[dq.front()][0]) dq.pop_front();
if (!dq.empty()) ret = max(ret, i - dq.front() + 1);
if (!dq.empty() && a[i][0] < a[dq.back()][0]) dq.pop_back();
dq.push_back(i);
}
printf("%d\n", ret);
return 0;
}