fork download
  1. /** Didn't work out :( */
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef long long int ll;
  5. int main()
  6. {
  7. ll n,j=0,i,ini=0;
  8. cin>>n;
  9. ll h[n+1];
  10. for(i=0;i<n;i++)
  11. {
  12. cin>>h[i];
  13. }
  14. ll count;i=0;
  15. ll countp=0,init;
  16. for(i=0;i<n;i++)
  17. {
  18. countp=0;
  19. for(j=0;j<n;j++)
  20. {
  21. if(h[i]==h[j])
  22. {
  23. countp++;
  24. }
  25. }
  26. if(i==0)
  27. {
  28. init=countp;
  29. }
  30. else if(countp>ini)
  31. {
  32. init=countp;
  33. }
  34. }
  35. for(i=0;i<=n-2;i++)
  36. {
  37. count=0;ll p1=h[i];
  38. for(j=i;j<n-1;j++)
  39. {
  40. if(h[j]>=min(h[i],h[i+1])&&h[j]<=max(h[i],h[i+1])&&h[j+1]<=max(h[i],h[i+1])&&h[j+1]>=min(h[i],h[i+1]))
  41. {
  42. count++;
  43. }
  44. }
  45. if(i==0)
  46. {
  47. ini=count;
  48. }
  49. else if(count>ini)
  50. {
  51. ini=count;
  52. }
  53. }
  54. if(ini>=init)
  55. {
  56. cout<<ini<<endl;
  57. }else{
  58. cout<<init<<endl;
  59. }
  60. }
  61.  
Success #stdin #stdout 0s 15240KB
stdin
5
1 2 3 2 3
stdout
3