Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. typedef unsigned int uint;
  4. int main(void){
  5.     uint N; cin>>N;
  6.     if(N<3){ // no solutions for inputs this short
  7.         cout<<0<<endl;
  8.         return 0;
  9.     }
  10.     uint* a=new uint[N];
  11.     for(uint i=0;i<N;++i)
  12.         cin>>a[i];
  13.  
  14.     uint minStart,minEnd,minDistance;
  15.     bool nomin=true;
  16.     for(uint start=0;start<N-2;++start)
  17.         for(uint end=start+2;end<N&&(nomin||end-start<minDistance);++end)
  18.             if(a[end-1]>a[start]&&a[end-1]>a[end]){
  19.                 if(nomin||end-start<minDistance){
  20.                     nomin=false;
  21.                     minDistance=end-start;
  22.                     minStart=start;
  23.                     minEnd=end;
  24.                 }
  25.                 break; // all further routes from this
  26.                        // starting point are longer
  27.             }
  28.  
  29.     if(nomin)
  30.         cout<<0<<endl;
  31.     else
  32.         cout<<minStart+1<<endl
  33.             <<minEnd+1  <<endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement