Coffee and Coursework (Easy version)
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The only difference between easy and hard versions is the constraints.

Polycarp has to write a coursework. The coursework consists of mm pages.

Polycarp also has nn cups of coffee. The coffee in the ii -th cup has aiai caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).

Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.

Let's consider some day of Polycarp's work. Consider Polycarp drinks kk cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are ai1,ai2,…,aikai1,ai2,…,aik . Then the first cup he drinks gives him energy to write ai1ai1 pages of coursework, the second cup gives him energy to write max(0,ai2−1)max(0,ai2−1) pages, the third cup gives him energy to write max(0,ai3−2)max(0,ai3−2) pages, ..., the kk -th cup gives him energy to write max(0,aik−k+1)max(0,aik−k+1) pages.

If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.

Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.

Input

The first line of the input contains two integers nn and mm (1≤n≤1001≤n≤100 , 1≤m≤1041≤m≤104 ) — the number of cups of coffee and the number of pages in the coursework.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100 ), where aiai is the caffeine dosage of coffee in the ii -th cup.

Output

If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.

Examples
Input

Copy
5 8
2 3 1 1 2
Output

Copy
4
Input

Copy
7 10
1 3 4 2 1 4 2
Output

Copy
2
Input

Copy
5 15
5 5 5 5 5
Output

Copy
1
Input

Copy
5 16
5 5 5 5 5
Output

Copy
2
Input

Copy
5 26
5 5 5 5 5
Output

Copy
-1
Note

In the first example Polycarp can drink fourth cup during first day (and write 11 page), first and second cups during second day (and write 2+(3−1)=42+(3−1)=4 pages), fifth cup during the third day (and write 22 pages) and third cup during the fourth day (and write 11 page) so the answer is 44 . It is obvious that there is no way to write the coursework in three or less days in this test.

In the second example Polycarp can drink third, fourth and second cups during first day (and write 4+(2−1)+(3−2)=64+(2−1)+(3−2)=6 pages) and sixth cup during second day (and write 44 pages) so the answer is 22 . It is obvious that Polycarp cannot write the whole coursework in one day in this test.

In the third example Polycarp can drink all cups of coffee during first day and write 5+(5−1)+(5−2)+(5−3)+(5−4)=155+(5−1)+(5−2)+(5−3)+(5−4)=15 pages of coursework.

In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5+(5−1)+(5−2)+(5−3)=145+(5−1)+(5−2)+(5−3)=14 pages of coursework and during second day he will write 55 pages of coursework. This is enough to complete it.

In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.

题意:

n杯咖啡,m页论文,每杯咖啡有自己的咖啡因含量a_{1}~a_{n},对应着喝完这杯咖啡能写页多少论文。在一天内喝第一杯咖啡,效果等于原值(ai的咖啡因量能肝ai页论文),每多喝一杯,这杯咖啡能产生的效果就会减一。问最少多少天完成论文?

 #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std; int main(int argc, char const *argv[])
{ int n,m;
cin>>n>>m; vector<int> a(n);
for( int i=; i<n; i++ ){
cin>>a[i];
} sort(a.rbegin(),a.rend());/*降序*/ for( int i=; i<=n; i++ ){/*天数*/
int sum=;
for( int j=; j<n; j++ ){
sum+=max(a[j]-j/i,);
}
if(sum>=m){
cout<<i<<endl;
return ;
}
}
cout<<-<<endl;
return ;
}

Coffee and Coursework (Easy version)的更多相关文章

  1. Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】

    任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...

  2. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)

    https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...

  3. 【Codeforces 1118D1】Coffee and Coursework (Easy version)

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 从小到大枚举天数. 然后贪心地,从大到小分配a[i]到各个天当中. a[n]分配到第1天,a[n-1]分配到第2天,...然后a[n-x]又分 ...

  4. Coffee and Coursework (Hard Version)

    Coffee and Coursework (Hard Version) time limit per test 2.5 seconds memory limit per test 256 megab ...

  5. Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)

    https://codeforces.com/contest/1118/problem/D2 和easy version的主要区别是,数据增加了. easy version采用的是线性查找,效率低 在 ...

  6. Codeforces - 1118D2 - Coffee and Coursework (Hard Version) - 二分

    https://codeforces.com/problemset/problem/1118/D2 也是很好想的一个二分啦. 验证m的可行性的时候,肯定是把最多咖啡因的咖啡先尽可能平均分到每一天,因为 ...

  7. Codeforces Round #540 (Div. 3) D2. Coffee and Coursework (Hard Version) (二分,贪心)

    题意:有\(n\)个数,每次可以选\(k(1\le k\le n)\)个数,并且得到\(a_1+max(0,a_2-1)+max(0,a_3-2)+...+max(0,a_k-k+1)\)的贡献,问最 ...

  8. Ping-Pong (Easy Version)(DFS)

    B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input ...

  9. ZOJ 3868 - Earthstone: Easy Version

    3868 - Earthstone: Easy Version Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld ...

随机推荐

  1. Lua模块的加载与内存释放

    今天早上听说一件事情让我觉得很诡异的事情:公司线上的一款游戏,加载一份配置资源后,内存涨了几十M,然后内存再也下不来了.因为好奇,所以要来了最大的一个配置文件(4.5M,去除空格与换行后的大小),进行 ...

  2. Centos yum国内源及配置含义

    Centos yum源的位置: /etc/yum.repos.d,可以通过配置文件/etc/yum.conf指定其他位置 主要的yum源种类:前两个是必须的,不然yum安装很多软件时会失败.yum本来 ...

  3. commit 冲突

    git status or repo sync . 时看到如下的提示: error: packages/apps/app/: branch alpha is published (but not me ...

  4. Android 读写权限,已经授权情况下,仍然(Permission denied)

    首次安装APP,获取读写权限以后, 当读取文件时候,仍然会遇见(Permission denied)错误,解决方案是杀掉APP,重新打开APP即可. 应该属于部分版本系统的bug,直到APP所有的pr ...

  5. Effective Java 第三版—— 85. 其他替代方式优于Java本身序列化

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  6. Nodejs 使用 es module (import/export)

  7. 伟哥对RTO & RPO的通俗理解

    RTO (Recovery Time Objective,复原时间目标)是企业可容许服务中断的时间长度.比如说灾难发生后半天内便需要恢复,RTO值就是十二小时: RPO (Recovery Point ...

  8. 在 Visual Studio 2017 新建的项目中,无法设置项目版本号的通配符规则

    错误信息:CS8357 指定的版本字符串中包含与确定性不兼容的通配符.从版本字符串删除通配符,或者禁用此编译的确定性 解决方法:删除项目文件中的配置,或将其设为 False :<Determin ...

  9. 根据IP查地理位置信息

    IP地址库下载地址: https://www.ipip.net/product/ip.html 使用方式(Python): https://github.com/ipipdotnet/datx-pyt ...

  10. 解决SVN 每次操作都需要重输入用户名密码问题

    把目录C:\Users\当前账号\AppData\Roaming\Subversion\auth下的文件删除,然后重启hbuilder或eclipse工具,重新输入账号密码之后,保存即可解决该问题.