Advertisement
fahimkamal63

Maximum Index

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