The Best Strategy

Carlo Ancelotti "Real Madrid's coach" is so Sad and disappointed, and Florentino Perez fired him after getting knocked out from the UEFA Champions League against Juventus. Carlo is so good in algorithms and strategies (he is an engineer), and he heard about the ACM competition and decided to train a team to qualify to ICPC. After 2 years of training Carlo became really experienced with his team, and now he knows how much time his team needs to solve a problem (read it and code it correctly). Given the required solving time for each problem, help Carlo to determine the highest number of problems his team can solve with the minimum possible penalty.

The total penalty is the sum of penalties for all solved problems. The penalty for a solved problem is equal to the number of minutes which have passed after the starting of the contest when this problem is submitted. And the period of the contest is 300 minutes.

Input

Your program will be tested on one or more test cases. The first line of the input contains a single integer T (1  ≤  T  ≤  100) the number of test cases. Followed by T test cases. Each test case consists of two lines. The first line contains a single integer N (8  ≤  N  ≤  15), the number of problems .The next line consists of Nintegers separated by a single space: pi (4  ≤ pi  ≤  300) which refers to the solving time for each problem.

Output

For each test case print the highest number of problems his team can solve and the minimum possible penalty.

Examples

Input

2
8
252 244 6 109 294 31 67 270
8
218 48 273 69 281 224 250 193

Output

4 360
2 165

AC代码(前缀和解决)

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t, n, i;
    int sum[20];
    int a[20];
    scanf("%d",&t);
    while(t--)
    {
        int sm = 0;
        memset(sum, 0, sizeof(sum));
        memset(a, 0, sizeof(a));
        scanf("%d",&n);
        for(i = 0; i<n; i++)
        scanf("%d",&a[i]);
        sort(a, a+n);
        for(i = 0; i<n; i++)
        {
            sm = sm + a[i];
            sum[i] = sm;
        }
        sm = 0;
        int sm1 = 0;
        for(i = 0; i<n; i++)
        {
            if(sum[i]<=300)
            {
                sm = sm + sum[i];
                sm1++;
            }
            else
                break;
        }
        printf("%d %d\n",sm1, sm);
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_41524782/article/details/81357781