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.

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 N integers separated by a single space: pi (4  ≤  pi  ≤  300) which refers to the solving time for each problem.

Output

For each test case print a single line containing "Case n:" (without the quotes) where n is the test case number (starting from 1) followed by a single space, followed by the number of problems his team can solve and the minimum possible penalty.

Examples

input

Copy

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

output

Copy

Case 1: 4 360
Case 2: 2 165

Note

The total penalty is the sum of penalties for all solved problems. The penalty for a solved problem is the time of the accepted submition. And the period of the contest is 300 minutes.

题意:先从大到小排序,时间相加,要是超过300,跳出,输出题数,和最大时间。

 

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    int n,i,j,a[100],b[100],t,s,o;
    scanf("%d",&t);
    for(o=0;o<t;o++)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        j=s=0;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        b[j++]=a[0];
        for(i=1;i<n;i++)
        {
            b[i]=a[i]+b[i-1];
            if(b[i]>300)
                break;
        }
        for(j=0;j<i;j++)
        {
            s+=b[j];
        }
        printf("Case %d: %d %d\n",o+1,i,s);
    }
    return 0;
}
 

 

posted @ 2018-04-15 12:47  ~~zcy  阅读(156)  评论(0编辑  收藏  举报