Advertisement
vovanhoangtuan

1433C - Dominant Piranha

Nov 26th, 2020
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void task(){
  6.     int n, maxA = 0;
  7.     cin >> n;
  8.     int a[n];
  9.     for (int i = 0; i < n; i++)
  10.     {
  11.         cin >> a[i];
  12.         maxA = max(a[i], maxA);
  13.     }
  14.     int temp = a[0];
  15.     bool check = false;
  16.     for (int i = 1; i < n; i++)
  17.     {
  18.         if (temp != a[i])
  19.         {
  20.             check = true;
  21.             break;
  22.         }
  23.     }
  24.  
  25.     if (check == false)
  26.     {
  27.         cout << "-1"  << endl;
  28.         return;
  29.     }
  30.  
  31.     for (int i = 0; i < n; i++)
  32.     {
  33.         if (a[i] == maxA)
  34.         {
  35.             if ((i - 1 >= 0 && a[i-1] < a[i] )|| (i + 1 < n && a[i + 1] < a[i]))
  36.             {
  37.                 cout << i + 1 << endl;
  38.                 return;
  39.             }
  40.         }
  41.     }
  42. }
  43.  
  44. int main()
  45. {
  46.     int t;
  47.     cin >> t;
  48.     while (t--) task();
  49.  
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement