A1322 | [COCI-2015_2016-contest6]#5 PUTOVANJE
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Young Mislav loves spending time in nature and, most of all, he loves spending time in forests. The fresh air and lovely sounds make the forest his favourite location. Mislav has decided to spend this afternoon in a forest and, because he’s so practical, he’s also decided to stuff himself with food. His belly can contain C amount of food.
He will have the opportunity to eat various fruits of nature (mushrooms, chestnuts, berries, and so on)
while walking through the forest. All fruits are mutually different given their type and he’d like to eat as much different fruits as possible, but with the condition that he doesn’t overeat. In other words, the total weight of the fruits he’s eaten must not be larger than C. Also, when Mislav decides to start eating, he tries to eat every next fruit if it’s possible to eat it and not overeat. In the case when he doesn’t have the capacity to eat it, he just moves on.
An array of weights of N fruits represents the weight and order of fruits that Mislav came across in the forest. Determine the maximum amount of different fruits that Mislav can eat.
He will have the opportunity to eat various fruits of nature (mushrooms, chestnuts, berries, and so on)
while walking through the forest. All fruits are mutually different given their type and he’d like to eat as much different fruits as possible, but with the condition that he doesn’t overeat. In other words, the total weight of the fruits he’s eaten must not be larger than C. Also, when Mislav decides to start eating, he tries to eat every next fruit if it’s possible to eat it and not overeat. In the case when he doesn’t have the capacity to eat it, he just moves on.
An array of weights of N fruits represents the weight and order of fruits that Mislav came across in the forest. Determine the maximum amount of different fruits that Mislav can eat.
输入格式
The first line of input contains two integers N and C (1 6 N 6 1 000, 1 6 C 6 1 000 000) from the task.
The second line contains N integers wi (1 6 wi 6 1000) that represent the fruits’ weight.
The second line contains N integers wi (1 6 wi 6 1000) that represent the fruits’ weight.
输出格式
The first and only line of output must contain the maximum possible amount of different fruits that Mislav can eat.
输入输出样例
输入 #1
5 5 3 1 2 1 1
输出 #1
4
输入 #2
7 5 1 5 4 3 2 1 1
输出 #2
3
输入 #3
5 10 3 2 5 4 3
输出 #3
3
Clarification of the first example: If Mislav decides to start eating from fruit (3), then he will have eaten
3 different fruits (3, 1, 1). If he starts eating from fruit (1), he will have eaten 4 fruits (1, 2, 1, 1).
3 different fruits (3, 1, 1). If he starts eating from fruit (1), he will have eaten 4 fruits (1, 2, 1, 1).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted