ICPC Balloons Solution

Problem

Chef is participating in an ICPC regional contest, in which there is a total of N problems (numbered 1 through N) with varying difficulties. For each valid i, the i-th easiest problem is problem A_i.

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 1 through 7. 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 1 through 7 (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 T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains a single integer N.
  • The second line contains N space-separated integers A_1, A_2, \ldots, A_N.

Output

For each test case, print a single line containing one integer ― the minimum number of problems Chef's team needs to solve.

Constraints

  • 1 \leq T \leq 10,500
  • 7 \leq N \leq 15
  • 1 \leq A_i \leq N for each valid i
  • A_1, A_2, \ldots, A_N are pairwise distinct

Sample 1:

Input
Output
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 7 problems, Chef's team will have to solve all of them.

Example case 2: Problems 1 through 7 appear among the first 8 problems.

Example case 3: Problems 1 through 7 again appear among the first 8 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;

}


Post a Comment

0 Comments