任意门:http://codeforces.com/contest/1118/problem/D1

D1. 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)=15pages 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 杯咖啡所具有的能量值,和需要看完的书。

喝一杯咖啡可以获得一定的能量值,看一页书消耗一个能量值,在一天内喝多次咖啡效果会递减,求最少多少天可以看完所有的书

解题思路:

一开始看错题目。。。以为是要喝完全部的咖啡并且刚好凑足所需的能量值。。。。

其实就是一道贪心水题,因为没有规定要喝完,而且只要能量值大于等于所需能量值即可。

枚举所需的最小天数,第 K 大的数在第 K 天用这样达到的结果肯定是最优的。

如果全部能量值加起来都不够说明无解。

AC code:

 #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int MAXN = ;
const int MAXM = 1e4+;
int num[MAXM];
int N, M;
bool cmp(int a, int b){return a > b;} int main()
{
int ans = ;
bool flag = false;
int tot = , cnt = ;
scanf("%d %d", &N, &M);
for(int i = ; i <= N; i++){
scanf("%d", &num[i]);
tot+=num[i];
}
if(tot < M) puts("-1");
else{
tot = ;
cnt = ;
sort(num+, num++N, cmp);
for(int ans = ; ans <= N; ans++){
tot = ;cnt = ;flag = false;
for(int i = ; i <= N; i++){
tot+=max(, num[i]-cnt);
if(i%ans == ) cnt++;
if(tot >= M){
flag = true;
break;
}
}
if(flag){
printf("%d\n", ans);
break;
}
}
}
return ;
}

Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】的更多相关文章

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

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

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

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

  3. 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)\)的贡献,问最 ...

  4. Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)

    D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...

  5. Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)

    F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...

  6. Codeforces Round #540 (Div. 3)--1118B - Tanya and Candies(easy TL!)

    Tanya has nn candies numbered from 11 to nn. The ii-th candy has the weight aiai. She plans to eat e ...

  7. Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

    题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...

  8. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  9. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

随机推荐

  1. sublime text 3支持GBK编码

    1.安装Package Control: 按Ctrl+~打开命令行,然后复制粘贴下面这一行代码,回车确定: import urllib.request,os; pf = 'Package Contro ...

  2. ASP.NET MVC4 新手入门教程之五 ---5.用控制器访问模型数据

    在本节中,将创建一个新的MoviesController类并编写代码来检索电影数据并将其显示在浏览器中使用一个视图模板. 才走出下一步生成应用程序. 用鼠标右键单击控制器文件夹中并创建一个新的 Mov ...

  3. [android] 练习viewpagerindicator的使用(一)

    主要是学习一下使用这个库 activity_main.xml <?xml version="1.0" encoding="utf-8"?> < ...

  4. Oracle 数据库字典 sys.col$ 表中关于type#的解释

    sys.col$ 表是oracle基础数据字典表中的列表,表中描述了数据库中各列信息,其中type#是列的数据类型.以下表格说明了各个数值的含义,以供参考. 值 说明 1 如果列 charsetfor ...

  5. 使用SSH连接LINUX的命令

    查看端口号是否被占用 netstat -tunlp|grep 端口号 杀掉 kill-9 pid 后台运行 nohup 应用程序名 & disown -a && exit 屏幕 ...

  6. Junit 单元测试、BeanUtils、Properties类

    一. Junit单元测试 1.1. Junit单元测试框架的基本使用 一.搭建环境: 导入junit.jar包(junit4) 二.写测试类: 0,一般一个类对应一个测试类. 1,测试类与被测试类最好 ...

  7. Sql-exec

    --显示sql server现有的所有数据库 exec sp_helpdb --查看数据表设置的约束 exec sp_helpconstraint SubjectType --update selec ...

  8. 09_dubbo服务发布原理

    [ 启动服务的日志分析 ] 1.暴露本地服务 Export dubbo service com.alibaba.dubbo.demo.DemoService to local registry, du ...

  9. MFC中利用Opencv与C++抓取摄像头进行人脸识别(Mat)

    原文:http://blog.csdn.net/mr_curry/article/details/51098311 第一次写博客哈哈,有些小激动,还请各位大神多多包涵~ 最近的项目需要用到人脸识别,作 ...

  10. Android中获取TextView行数

    项目中发现,如果直接通过TextView.getLineCount()方法获取行数时,总是0,研究发现,setText()后立即调用getLineCount(), 这时TextView还未完成meas ...