Advertisement
fahimkamal63

Maximum index

Dec 17th, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<cstdio>
  2. using namespace std;
  3. int main(){
  4.     int t;
  5.     scanf("%d", &t);
  6.     while(t--){
  7.         int n; scanf("%d", &n);
  8.         int a[n++], i;
  9.         for(i = 1; i < n; i++){
  10.             scanf("%d", &a[i]);
  11.         }
  12.         int difference = 0, j, temp;
  13.         for(i = 1; i < n; i++){
  14.             for(j = n-1; j > i; j--){
  15.                 if(a[i] <= a[j]){
  16.                     temp = j - i;
  17.                     difference = max(difference, temp);
  18.                     break;
  19.                 }
  20.             }
  21.         }
  22.         printf("%d \n", difference);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement