zoukankan      html  css  js  c++  java
  • A

    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 (1n1031≤n≤103, 1s10121≤s≤1012) — the number of kegs and glass volume.

    The second line contains nn integers v1,v2,,vnv1,v2,…,vn (1vi1091≤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
    3 3
    4 3 5
    Output
    3
    Input
    3 4
    5 3 4
    Output
    2
    Input
    3 7
    1 2 3
    Output
    -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 33 liters 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.

     1 #include <cstdio>
     2 #include <iostream>
     3 
     4 using namespace std;
     5 
     6 long long v[1005];
     7 
     8 int main()
     9 {
    10     long long n;
    11     long long s;
    12     scanf("%lld %lld",&n,&s);
    13     for(int i=0;i<n;++i)
    14     {
    15         scanf("%lld",&v[i]);
    16     }
    17 
    18     long long min_v=v[0];
    19     for(int i=1;i<n;++i)
    20     {
    21         if(min_v>v[i])
    22         {
    23             min_v=v[i];
    24         }
    25     }
    26 
    27     long long sum=0;
    28     for(int i=0;i<n;++i)
    29     {
    30         sum+=v[i]-min_v;
    31     }
    32 
    33     long long left=0,right=min_v,k=-1;
    34 
    35     while(left<=right)
    36     {
    37         long long mid=(left+right)>>1;
    38         if(sum+(min_v-mid)*n >= s)
    39         {
    40             k=max(mid,k);
    41             left=mid+1;
    42         }
    43         else
    44         {
    45             right=mid-1;
    46         }
    47     }
    48 
    49     printf("%d
    ",k);
    50 
    51 
    52 
    53     return 0;
    54 }
  • 相关阅读:
    WeQuant交易策略—NATR
    WeQuant交易策略—网格交易
    免交易手续费的数字货币交易所
    WeQuant交易策略—ATR
    WeQuant交易策略—RSI
    WeQuant交易策略—BOLL
    WeQuant交易策略—KDJ
    WeQuant交易策略—MACD
    WeQuant交易策略—EMA指标
    WeQuant交易策略—简单均线
  • 原文地址:https://www.cnblogs.com/jishuren/p/12239081.html
Copyright © 2011-2022 走看看