Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to “All World Classical Singing Festival”. Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn’t need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
The duration of the event must be no more than d minutes;
Devu must complete all his songs;
With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 ≤ n ≤ 100; 1 ≤ d ≤ 10000). The second line contains n space-separated integers: t1, t2, …, tn (1 ≤ ti ≤ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
问题分析:先判断能否在规定时间内完成演奏,如果能,就用总时间减去休息时间再对讲笑话的时间求余,取整。
AC通过的代码如下:
#include<iostream>
using namespace std;
int main()
{
int n, d,i,a,s=0;
cin >> n >> d;
for(i=1;i<=n;i++)
{
cin >> a;
s += a;
}if (s + 10 * (n - 1) > d)cout << "-1" << endl;
else cout << (d - s) / 5 << endl;
return 0;
}