Problem
Chef is participating in an ICPC regional contest, in which there is a total of problems (numbered through ) with varying difficulties. For each valid , the -th easiest problem is problem .
After a team solves a problem, a balloon with a colour representing that problem is tied next to their desk. Chef is fond of colours in VIBGYOR, which are representative of the problems with numbers through . The remaining problems have their own representative colours too.
Find the minimum number of problems which Chef's team needs to solve in order to get all the balloons for problems through (and possibly some other balloons too) tied next to their desk, if you know that Chef's team knows the difficulties of all problems and solves the problems in increasing order of difficulty.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers .
Output
For each test case, print a single line containing one integer ― the minimum number of problems Chef's team needs to solve.
Constraints
- for each valid
- are pairwise distinct
Sample 1:
3 7 1 2 3 4 5 7 6 8 8 7 6 5 4 3 2 1 9 7 4 3 5 6 1 8 2 9
7 8 8
Explanation:
Example case 1: Since there are a total of problems, Chef's team will have to solve all of them.
Example case 2: Problems through appear among the first problems.
Example case 3: Problems through again appear among the first problems.
Program :
#include <stdio.h>
int main(void)
{
int t,i;
scanf("%d",&t);
while(t>0)
{
int n,count=0,ans=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]<=7)
count++;
if(count==7)
{
ans=i;
break;
}
}
printf("%d\n",ans+1);
t--;
}
// your code goes here
return 0;
}
0 Comments