Advertisement
SuitNdtie

Climbing Monkey

May 31st, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<algorithm>
  3. using namespace std;
  4. typedef long long int ll;
  5. struct edge{
  6.     int h;
  7.     int l,r;
  8. };
  9. bool mycmp(edge a,edge b){
  10.     return a.h < b.h;
  11. }
  12. int illusion[200010];
  13.  
  14. int main()
  15. {
  16.     //  freopen("input_cm03.txt","r",stdin);
  17.     int n,m,k;
  18.     scanf("%d %d %d",&m,&n,&k);
  19.     ll ban[n+1];
  20.     for(int i = 1 ; i <= n ; i ++){
  21.         scanf("%lld ",&ban[i]);
  22.     }
  23.     edge ae[k];
  24.     for(int i = 0 ; i < k ; i ++){
  25.         int l,h;
  26.         scanf("%d %d",&l,&h);
  27.         ae[i] = {h,l,l+1};
  28.     }
  29.     sort(ae,ae+k,mycmp);
  30.     int start;
  31.     scanf("%d",&start);
  32.     int X = start;
  33.     illusion[X - 1] = 1;
  34.     illusion[X + 1] = 1;
  35.     for(int i = 0 ; i < k ; i ++){
  36.         int L = ae[i].l;
  37.         int R = ae[i].r;
  38.         int H = ae[i].h;
  39.         bool check = true;
  40.         swap(illusion[L],illusion[R]);
  41.         if(X == L){
  42.             illusion[L] = 1;
  43.             X = R;
  44.             illusion[X - 1] = 1;
  45.             illusion[X + 1] = 1;
  46.         }
  47.         else if(X == R){
  48.             illusion[R] = 1;
  49.             X = L;
  50.             illusion[X - 1] = 1;
  51.             illusion[X + 1] = 1;
  52.         }
  53.         else if(L-1 >= 1 && X == L - 1){
  54.             illusion[L] = 1;
  55.         }
  56.         else if(R+1 <= n && X == R + 1){
  57.             illusion[R] = 1;
  58.         }
  59.         else{
  60.             check = false;
  61.         }
  62.         //if(check)printf("Test edge #%d : h(%d),at(%d,%d)\n",i,H,L,R);
  63.     }
  64.     ll maxa = ban[X];
  65.     bool stick = false;
  66.     illusion[X-1] = 1;
  67.     illusion[X+1] = 1;
  68.     for(int i = 1 ; i <= n ; i ++){
  69.     //  printf("%d ",illusion[i]);
  70.         if(illusion[i] == 1){
  71.             if(ban[i] > maxa){
  72.                 maxa = ban[i];
  73.                 stick = true;
  74.             }
  75.         }
  76.     }//printf("\n");
  77.     printf("%lld\n%s",maxa,(stick?"USE":"NO"));
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement