Advertisement
Guest User

ois_70-100

a guest
Aug 8th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #define max(a,b) (a>b ? a : b)
  3. #define min(a,b) (a<b ? a : b)
  4. #define MAXN 100000
  5.  
  6. int osserva(int N, int H[])
  7. {
  8.     int l, r, S=0;
  9.     for(int i=0; i<N; i++)
  10.     {
  11.         for(l=max(0, i-1); l>0 && H[l]<H[i]; l--);
  12.         for(r=min(N-1,i+1); r<N-1 && H[r]<H[i]; r++);
  13.         S = max(r-l+1, S);
  14.     }
  15.     return S;
  16. }
  17.  
  18. int H[MAXN];
  19.  
  20. int main()
  21. {
  22.     FILE *fr, *fw;
  23.     int N, i;
  24.  
  25.     fr = fopen("input.txt", "r");
  26.     fw = fopen("output.txt", "w");
  27.  
  28.     fscanf(fr, "%d\n", &N);
  29.     for(i=0; i<N; i++)
  30.         fscanf(fr, "%d ", &H[i]);
  31.     fprintf(fw, "%d\n", osserva(N, H));
  32.  
  33.     fclose(fr);
  34.     fclose(fw);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement