CodeForces 140DNew Year Contest

来源:互联网 发布:php判断是否为素数 编辑:程序博客网 时间:2024/06/06 02:36


D - New Year Contest
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 140D

Description

As Gerald sets the table, Alexander sends the greeting cards, and Sergey and his twins create an army of clone snowmen, Gennady writes a New Year contest.

The New Year contest begins at 18:00 (6.00 P.M.) on December 31 and ends at 6:00 (6.00 A.M.) on January 1. There are n problems for the contest. The penalty time for each solved problem is set as the distance from the moment of solution submission to the New Year in minutes. For example, the problem submitted at 21:00 (9.00 P.M.) gets penalty time 180, as well as the problem submitted at 3:00 (3.00 A.M.). The total penalty time is calculated as the sum of penalty time for all solved problems. It is allowed to submit a problem exactly at the end of the contest, at 6:00 (6.00 A.M.).

Gennady opened the problems exactly at 18:00 (6.00 P.M.) and managed to estimate their complexity during the first 10 minutes of the contest. He believes that writing a solution for the i-th problem will take ai minutes. Gennady can submit a solution for evaluation at any time after he completes writing it. Probably he will have to distract from writing some solution to send the solutions of other problems for evaluation. The time needed to send the solutions can be neglected, i.e. this time can be considered to equal zero. Gennady can simultaneously submit multiple solutions. Besides, he can move at any time from writing one problem to another, and then return to the first problem from the very same place, where he has left it. Thus the total solution writing time of the i-th problem always equals aiminutes. Of course, Gennady does not commit wrong attempts, and his solutions are always correct and are accepted from the first attempt. He can begin to write the solutions starting from 18:10 (6.10 P.M.).

Help Gennady choose from the strategies that help him solve the maximum possible number of problems, the one with which his total penalty time will be minimum.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of the problems. The next line contains n space-separated integers ai(1 ≤ ai ≤ 720) — each number shows how much time in minutes Gennady will spend writing a solution to the problem.

Output

Print two integers — the number of problems Gennady will solve and the total penalty time considering that he chooses the optimal strategy.

Sample Input

Input
330 330 720
Output
2 10

Hint

In the sample, one of Gennady's possible optimal strategies is as follows. At 18:10 (6:10 PM) he begins to write the first problem and solves it in 30 minutes (18:40 or 6.40 P.M.). At 18:40 (6.40 P.M.) he begins to write the second problem. There are 320 minutes left before the New Year, so Gennady does not have the time to finish writing the second problem before the New Year. At 0:00 (12.00 A.M.) he distracts from the second problem, submits the first one, and returns immediately to writing the second problem. At 0:10 (0.10 A.M.), he completes the solution for the second problem, submits it and gets 10 minute penalty time. Note that as the total duration of the contest is 720 minutes and Gennady has already spent 10 minutes on reading the problems, he will not have time to solve the third problem during the contest. Yes, such problems happen to exist.

Competitions by the given rules are held annually on the site http://b23.ru/3wvc


原来这么多水题都没看............

题意:第一个输入n表示n道题,之后n个数表示每道题所要花费的时间。比赛从18:00开始,前10分钟需要估测题目难度,也就是说实际上从18:10开始做题。在0点之后做完的题会有一个罚时,罚时的时间就是距离0:00的时间。现在问你所能做的最多的题数和能获得的最少罚时是多少。当然我们认为他可以随时换题目敲,并且在0.00的罚时是0.

思路:既然在0点的罚时是0,并且可以选择提交时间,那么我们只要认为他在0点之前做的题没有罚时就可以了,因为之前做完的题完全可以直接在0点交。这样我们把时间花费从小到大排序就可以了,挨着做这样就是做最多的题,而且最少的罚时了。因为这样做0点之后做完的题一定会比之前做完的题少,计算罚时自然也会相应的少了。(别深究,会疯的读者可以自己画个图看看)

类似这样:


我们应当尽量的让右边的端点少,(想一想为什么),因为你不管怎么安排两端都会到起点和终点的,然后每次计算罚时,端点越多,就会多加和前面端点重合的部分的长度。

#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int a[110];int main(){    int n;    int i;    scanf("%d",&n);    for(i=0;i<n;++i)scanf("%d",&a[i]);    //sort(a,a+n);    int sum=10;    int ans1=0,ans2=0;    for(i=0;i<n;++i)    {        if(sum+a[i]<=360)        {            sum+=a[i];            ans1++;        }        else        {            if(sum+a[i]>720)break;            ans1++;            sum+=a[i];            ans2+=sum-360;        }    }    printf("%d %d\n",ans1,ans2);    return 0;}




1 0
原创粉丝点击