Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using p=pair<int,int>;
  4.  
  5. bool compare (p a,p b){
  6. return a.first<b.first;
  7. }
  8.  
  9. int main(){
  10.  
  11. int n;
  12. scanf("%d",&n);
  13. vector <p> v;
  14. for(int i=1;i<=n;i++){
  15. int s,t;
  16. scanf("%d %d",&s,&t);
  17. v.push_back({s,i});
  18. v.push_back({t,i});
  19. }
  20. sort(v.begin(),v.end(),compare);
  21. stack <int> st;
  22. bool check=true;
  23. for(int i=0;i<v.size();i++){
  24. int x=v[i].second;
  25. if(st.size()==0 || st.top()!=x) st.push(x);
  26. else if(st.top()==x) st.pop();
  27. else check=false;
  28. }
  29. if(check==true && st.size()==0) printf("Yes");
  30. else printf("No");
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement