Advertisement
IlidanBabyRage

elephants.cpp

Jun 12th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int MAX = 5001;
  6.  
  7. int main(){
  8.    
  9.     int n, tmp, maxi = -1, mini = -1, max, min;
  10.     int ar[100000];
  11.  
  12.     cin >> n;
  13.  
  14.     for (int i = 0; i < n; i++){
  15.         cin >> ar[i];
  16.     }
  17.     min = MAX;
  18.     max = -1;
  19.     for (int i = 0; i < n - 1; i++){
  20.         while (i < (n - 1) && ar[i] >= min)
  21.             i++;
  22.         while (i < (n - 1) && ar[i + 1] <= ar[i])
  23.             i++;
  24.         if (i > maxi){
  25.             int tmpmax = -1;
  26.             int tmpmaxi;
  27.             for (int j = i + 1; j < n; j++){
  28.                 if (ar[j] > tmpmax){
  29.                     tmpmaxi = j;
  30.                     tmpmax = ar[j];
  31.                 }
  32.             }
  33.             if (tmpmax * min > ar[i] * max){
  34.                 max = tmpmax;
  35.                 min = ar[i];
  36.                 maxi = tmpmaxi;
  37.                 mini = i;
  38.             }
  39.         }else{
  40.             if (ar[i] < min){
  41.                 min = ar[i];
  42.                 mini = i;
  43.             }
  44.         }
  45.     }
  46.  
  47.     if (min >= max){
  48.         cout << 0 << " " << 0 << endl;
  49.     }else{
  50.         cout << mini + 1 << " " << maxi + 1 << endl;
  51.     }
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement