B. Kvass and the Fair Nut

B. Kvass and the Fair Nut

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The Fair Nut likes kvass very much. On his birthday parents presented
him nn kegs of kvass. There are vivi liters of kvass in the ii-th keg.
Each keg has a lever. You can pour your glass by exactly 11 liter
pulling this lever. The Fair Nut likes this drink very much, so he
wants to pour his glass by ss liters of kvass. But he wants to do it,
so kvass level in the least keg is as much as possible.

Help him find out how much kvass can be in the least keg or define
it’s not possible to pour his glass by ss liters of kvass.

Input

The first line contains two integers nn and ss (1≤n≤1031≤n≤103,
1≤s≤10121≤s≤1012) — the number of kegs and glass volume.

The second line contains nn integers v1,v2,…,vnv1,v2,…,vn
(1≤vi≤1091≤vi≤109) — the volume of ii-th keg.

Output

If the Fair Nut cannot pour his glass by ss liters of kvass, print
−1−1. Otherwise, print a single integer — how much kvass in the least
keg can be.

Examples

input

Copy

3 3
4 3 5
output

Copy

3
input

Copy

3 4
5 3 4
output

Copy

2
input

Copy

3 7
1 2 3
output

Copy

-1

Note

In the first example, the answer is 33, the Fair Nut can take 11 liter
from the first keg and 22 liters from the third keg. There are
33liters of kvass in each keg. In the second example, the answer is
22, the Fair Nut can take 33 liters from the first keg and 11 liter
from the second keg.

In the third example, the Fair Nut can’t pour his cup by 77 liters, so
the answer is −1−1.

思路如下

  • 题意:跟我们n桶酒,每桶酒的体积为ar[ i ] , 然后又给我们一个杯子,问我们用这 n 桶酒倒满(有些桶里的酒可以不用)所给的杯子,在剩下的n桶酒中剩的最少体积的酒的那桶,最多可以剩多少酒。
  • 思路:直接看代码注释

题解如下

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int Len = 1005;
int ar[Len];

int main()
{
    //freopen("test.txt","r",stdin);
    long long int n,s;
    scanf("%lld %lld",&n,&s);
    long long int sum = 0;		//n桶酒的总体积

    for(int i = 0; i < n; i ++)
    {
        scanf("%d",&ar[i]);
        sum += ar[i];
    }
    if(sum >= s)
    {
        sort(ar , ar + n);
        long long sur = sum - ar[0] * n;	//sur 为在n桶里面每桶中多余ar[0]的部分之和
        if(sur >= s)		//可以直接到满,直接输出最小值
        {
            printf("%d",ar[0]);
        }
        else
        {
            s -= sur;
            long long all = n * ar[0];
            all -= s;
            printf("%lld",all/n);
        }
    }
    else
        cout<<-1;

    return 0;
}
发布了84 篇原创文章 · 获赞 120 · 访问量 8650

猜你喜欢

转载自blog.csdn.net/qq_34261446/article/details/104092971