Untitled

 avatar
ducsieumanh1hitlanamguku
plain_text
13 days ago
1.1 kB
3
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
pair <int,int> pt[1000006];
int t[1000006],t2[1000006];
int n;
bool l[1000006],r[1000006];
int main() {
	cin>>n;
	for (int i=1;i<=n;i++) { //nhap+tinh thua
		cin>>pt[i].first>>pt[i].second;
        t[i]=pt[i].first-pt[i].second;
	}
    for (int i=1;i<=n;i++) {
        int tx;
        if (i-1==0) tx=n;
        else tx=i-1;
        t2[i]=pt[i].first-pt[tx].second;
    }
	for (int i=1;i<=n;i++) {
        if (t[i]<0) {
            int giatri=t[i];
            int x=i-1;
            while (giatri<0) {
                r[x+1]=1;
                if (x==1) x=n;
                giatri+=t[x];
                x--;
            }
        }
    }
    for (int i=n;i>=1;i--) {
        if (t2[i]<0) {
            int giatri=t2[i];
            int x=i+1;
            while (giatri<0) {
                l[x-1]=1;
                if (x==n) x=1;
                giatri+=t2[x];
                x++;
            }
        }
    }
    for (int i=1;i<=n;i++) {
        if (l[i]==1&&r[i]==1) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
}
Leave a Comment