D. Animals
time limit per test

2 seconds

memory limit per test

64 megabytes

input

input.txt

output

output.txt

Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of
the drink and, having come home, he went to bed at once.

DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly n days
in DravDe’s dream and the animal that came on the i-th day, ate exactly ci tons
of food daily starting from day i. But if one day the animal could not get the food it needed, it got really sad. At the very beginning
of the dream there were exactly X tons of food on the farm.

DravDe woke up terrified...

When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the n-th day any more, but he
did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out.

It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that
day to the n-th.

Input

The first input line contains integers n and X (1 ≤ n ≤ 100, 1 ≤ X ≤ 104)
— amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers ci (1 ≤ ci ≤ 300).
Numbers in the second line are divided by a space.

Output

Output the only number — the maximum possible amount of animals on the farm by the end of the n-th day given that the food was enough
for everybody.

Examples
input
3 4
1 1 1
output
2
input
3 6
1 1 1
output
3
Note

Note to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day.

很有意思的一题,因为大家都没有做出来,比赛快结束时才知道要用

freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);    原来是水题,不过思路还是得清晰一点,,简化题意就是如果要容纳这只动物,那么就得吃到最后一天而且不会unhappy,就先把每只动物到最后一天所需的粮食求出来,再排序一下,,,然后贪心策略;

 
   上代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N=500;
int n,m,a[N];
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int i;
while(~scanf("%d%d",&n,&m))
{
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
a[i]*=(n-i);//每只动物总共所需的粮食;
}
sort(a,a+n);
printf("\n");
if(a[0]>m)
printf("0\n");
else
{
int k=0;
for(i=0;i<n;i++)
{
if(m-a[i]>=0)
{
k++;
m-=a[i];
}
else
break;
}
printf("%d\n",k);
}
}
return 0;
}

『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals的更多相关文章

  1. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]-最小内积(第八届北京师范大学程序设计竞赛决赛)

    H. 最小内积                                                                   Time Limit: 1000ms Memory ...

  2. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)

    A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. 第九届河南理工大学算法程序设计大赛 正式赛L:最优规划(最小生成树)

    单测试点时限: 1.0 秒 内存限制: 512 MB 有很多城市之间已经建立了路径,但是有些城市之间没有路径联通.为了联通所有的城市,现在需要添加一些路径,为了节约,需要满足添加总路径是最短的. 输入 ...

  4. 『PyTorch』第九弹_前馈网络简化写法

    『PyTorch』第四弹_通过LeNet初识pytorch神经网络_上 『PyTorch』第四弹_通过LeNet初识pytorch神经网络_下 在前面的例子中,基本上都是将每一层的输出直接作为下一层的 ...

  5. 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 237C,素数打表,二分查找

    C. Primes on Interval time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 236A,虽然很水,但有一个很简单的函数用起来方便

    A. Boy or Girl time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]CF-236B. Easy Number Challenge

    B. Easy Number Challenge time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛 C-Cities

    题目描述:There are n cities in Byteland, and the ith city has a value ai. The cost of building a bidirec ...

  9. “浪潮杯”第九届山东省ACM大学生程序设计竞赛(重现赛)E.sequence(树状数组求逆序对(划掉))

    传送门 E.sequence •题意 定义序列 p 中的 "good",只要 i 之前存在 pj < pi,那么,pi就是 "good": 求删除一个数, ...

随机推荐

  1. css新奇技术及其未来发展

    1.图像替换技术: 图像替换技术是指使用图像替换页面中文本的功能,类似与在页面中插入图像,只是这种方法更为方便,易于代码管理.通常来说,设计者习惯使用有意义的图像去替换一些标题,logo和某些特定的页 ...

  2. (025)[系统故障]XP下禁止将串口设备识别成鼠标(转)

    很多人都遇到过这种问题:Windows XP启动时将一台连续发送数据的串口设备识别成串口鼠标,自动安装了串口鼠标驱动,而设备因此无法正常工作,而光标则无规律地到处跑.对此问题,Internet上的方法 ...

  3. iOS 项目代码组织

    参考了很多系列,发现老外们都比较喜欢 group by type,这两个还不错: http://akosma.com/2009/07/28/code-organization-in-xcode-pro ...

  4. ASP.NET Web API 2 框架揭秘

    这不是一本传统意义上的入门书籍 任何 —本书都具有对应的受众群体,所以我不得不将这句话放在最前面,并且希望所有 打算购买此书的读者能够看到.如果你之前对As氵NET W山API(或者AsPNET MⅤ ...

  5. canvas基础绘制-绚丽倒计时

    效果图: html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  6. python中的格式化字符

    python中的格式化字符在python中我们会遇到一个问题,问题是如何输出格式化的字符串.我们经常会输出类似'亲爱的xxx你好!你xx月的话费是xx,余额是xx'之类的字符串,而xxx的内容都是根据 ...

  7. Redis学习笔记(三)列表进阶

    RPOPLPUSH source destination(弹出source列表最右端的元素,并推入destination的最左端,同时返回这个元素) BRPOPLPUSH source destina ...

  8. JDBC性能优化篇

    系统性能. 少用Metadata方法     与其它的JDBC方法相比, 由ResultSet对象生成的metadata对象的相对来说是很慢的. 应用程序应该缓存从ResultSet返回的metada ...

  9. http以及http协议简单理解

    HTTP协议是超文本传输协议的缩写,是用于从万维网(WWW)服务器传输超文本到本地浏览器的传送协议:HTTP是一个基于TCP/IP通信协议来传递数据(HTML文件, 图片文件, 查询结果等)HTTP作 ...

  10. Python 使用re模块实现正则表达式

    # coding: utf-8 # Team : Quality Management Center # Author:Carson # Date :2019/6/21 10:41 # Tool :P ...