CF1118D1.Coffee and Coursework (Easy version)
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has ai 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 k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are ai1,ai2,…,aik. Then the first cup he drinks gives him energy to write ai1 pages of coursework, the second cup gives him energy to write max(0,ai2−1) pages, the third cup gives him energy to write max(0,ai3−2) pages, ..., the k-th cup gives him energy to write 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.
简单版本与困难版本的唯一区别在于约束条件。
波利卡普需要完成一篇课程论文。该论文共包含 m 页。
波利卡普还有 n 杯咖啡。第 i 杯咖啡含有 ai 单位的咖啡因。波利卡普可以饮用其中若干杯咖啡(每杯最多饮用一次),且饮用顺序可以任意。他每次饮用一杯咖啡都是瞬间且完全喝完的(即他不能将某一杯咖啡分到多天饮用)。
当然,课程论文通常不是在一天内写完的(至少在贝尔兰这个理想世界中是这样)。有些论文需要连续多日的刻苦工作。
我们来考虑波利卡普工作的某一天。假设他在这一天饮用了 k 杯咖啡,所饮用咖啡的咖啡因含量依次为 ai1,ai2,…,aik。那么:
- 第一杯咖啡使他获得撰写 ai1 页论文的能量;
- 第二杯咖啡使他获得撰写 max(0,ai2−1) 页论文的能量;
- 第三杯咖啡使他获得撰写 max(0,ai3−2) 页论文的能量;
- ……
- 第 k 杯咖啡使他获得撰写 max(0,aik−k+1) 页论文的能量。
如果波利卡普在某一天不喝咖啡,则当天他完全无法撰写论文。
波利卡普希望尽快完成论文(即花费最少的天数)。你的任务是求出这个最少天数,或者判断这是不可能的。
输入格式
The first line of the input contains two integers n and m (1≤n≤100, 1≤m≤104) — the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤100), where ai is the caffeine dosage of coffee in the i-th cup.
输入的第一行包含两个整数 n 和 m(1≤n≤100,1≤m≤104)——分别表示咖啡杯数和课程作业的页数。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤100),其中 ai 表示第 i 杯咖啡的咖啡因剂量。
输出格式
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
如果无法完成该课程作业,则输出 -1;否则输出 Polycarp 完成该作业所需的最少天数。
输入输出样例
输入#1
5 8 2 3 1 1 2
输出#1
4
输入#2
7 10 1 3 4 2 1 4 2
输出#2
2
输入#3
5 15 5 5 5 5 5
输出#3
1
输入#4
5 16 5 5 5 5 5
输出#4
2
输入#5
5 26 5 5 5 5 5
输出#5
-1
说明/提示
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2+(3−1)=4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. 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)=6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. 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)=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)=14 pages of coursework and during second day he will write 5 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.
在第一个例子中,Polycarp 可以在第一天喝第四杯咖啡(写出 1 页),第二天喝第一和第二杯咖啡(写出 2+(3−1)=4 页),第三天喝第五杯咖啡(写出 2 页),第四天喝第三杯咖啡(写出 1 页),因此答案为 4。显然,在该测试用例中,不存在用三天或更少天数完成课程作业的方法。
在第二个例子中,Polycarp 可以在第一天喝第三、第四和第二杯咖啡(写出 4+(2−1)+(3−2)=6 页),第二天喝第六杯咖啡(写出 4 页),因此答案为 2。显然,在该测试用例中,Polycarp 无法在一天内完成全部课程作业。
在第三个例子中,Polycarp 可以在第一天喝完所有咖啡,写出 5+(5−1)+(5−2)+(5−3)+(5−4)=15 页课程作业。
在第四个例子中,Polycarp 无法在第一天喝完所有咖啡,必须将其中一杯留到第二天饮用。因此,他第一天将写出 5+(5−1)+(5−2)+(5−3)=14 页课程作业,第二天将写出 5 页课程作业。这已足够完成全部任务。
在第五个例子中,Polycarp 根本无法完成全部课程作业,即使他每天只喝一杯咖啡,因此答案为 -1。
输入解题思路,AI测评打分。不知道怎么写?