Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef unsigned int uint;
- int main(void){
- uint N; cin>>N;
- if(N<3){ // no solutions for inputs this short
- cout<<0<<endl;
- return 0;
- }
- uint* a=new uint[N];
- for(uint i=0;i<N;++i)
- cin>>a[i];
- uint minStart,minEnd,minDistance;
- bool nomin=true;
- for(uint start=0;start<N-2;++start)
- for(uint end=start+2;end<N&&(nomin||end-start<minDistance);++end)
- if(a[end-1]>a[start]&&a[end-1]>a[end]){
- if(nomin||end-start<minDistance){
- nomin=false;
- minDistance=end-start;
- minStart=start;
- minEnd=end;
- }
- break; // all further routes from this
- // starting point are longer
- }
- if(nomin)
- cout<<0<<endl;
- else
- cout<<minStart+1<<endl
- <<minEnd+1 <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement