YEZAELP

SMMR-120: My Heart Flutters

Jul 7th, 2020 (edited)
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int N = 3e3;
  5. int ar[N+10];
  6. int in[N+10];
  7. int de[N+10];
  8.  
  9. int main(){
  10.  
  11.     int n;
  12.     scanf("%d", &n);
  13.  
  14.     for(int i=1;i<=n;i++) scanf("%d", &ar[i]);
  15.  
  16.     int mx = 0;
  17.     for(int i=1;i<=n;i++){
  18.         in[i] = 1;
  19.         de[i] = 1;
  20.         for(int j=1;j<i;j++){
  21.             if(ar[j] < ar[i]) in[i] = max(de[j] + 1, in[i]);
  22.             if(ar[j] > ar[i]) de[i] = max(in[j] + 1, de[i]);
  23.         }
  24.         mx = max(mx, in[i]);
  25.         mx = max(mx, de[i]);
  26.     }
  27.  
  28.     printf("%d", mx);
  29.  
  30.     return 0;
  31. }
  32.  
RAW Paste Data Copied