1. 程式人生 > >Codeforces Round #251(Div. 2) 439A. Devu, the Singer and Churu, the Joker 水題

Codeforces Round #251(Div. 2) 439A. Devu, the Singer and Churu, the Joker 水題

A. Devu, the Singer and Churu, the Joker time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

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.

Examples input
3 30
2 2 1
output
5
input
3 20
2 1 1
output
-1
題意:
一個歌手演唱n首歌曲,第i首歌需要唱Ti分鐘,每唱完一首歌歌手需要休息10分鐘,另外一個人會講笑話,一個笑話講5分鐘,兩人不能同時進行。
問時間長度為d的演唱會,歌手能否唱完n首歌,能的話輸出期間能講的笑話的最大值,否則輸出-1
題解:
模擬,不唱歌的時間全都用來講笑話。

/****************
*PID:439a div2
*Auth:Jonariguez
*****************
*/
#define lson k*2,l,m
#define rson k*2+1,m+1,r
#define rep(i,s,e) for(i=(s);i<=(e);i++)
#define For(j,s,e) For(j=(s);j<(e);j++)
#define sc(x) scanf("%d",&x)
#define In(x) scanf("%I64d",&x)
#define pf(x) printf("%d",x)
#define pfn(x) printf("%d\n",(x))
#define Pf(x) printf("%I64d",(x))
#define Pfn(x) printf("%I64d\n",(x))
#define Pc printf(" ")
#define PY puts("YES")
#define PN puts("NO")
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef int Ll;
Ll quick_pow(Ll a,Ll b,Ll MOD){a%=MOD;Ll res=1;while(b){if(b&1)res=(res*a)%MOD;b/=2;a=(a*a)%MOD;}return res;}

const int maxn=100000+10;
int a[maxn];

int main()
{
    int i,j,n,m,d;
    while(scanf("%d%d",&n,&d)!=EOF){
        int sum=0;
        for(i=1;i<=n;i++){
            sc(a[i]);
            sum+=a[i];
        }
        sum+=(n-1)*10;
        if(sum>d){
            puts("-1");continue;
        }
        sum-=(n-1)*10;
        printf("%d\n",(d-sum)/5);
    }
    return 0;
}