A - Valera and Fruits
来源:互联网 发布:js获取map的value 编辑:程序博客网 时间:2024/05/17 05:52
Description
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more thanv fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
Input
The first line contains two space-separated integers n and v(1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi(1 ≤ ai, bi ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
Output
Print a single integer — the maximum number of fruit that Valera can collect.
Sample Input
2 31 52 3
8
5 103 202 201 204 205 20
60
Hint
In the first sample, in order to obtain the optimal answer, you should act as follows.
- On the first day collect 3 fruits from the 1-st tree.
- On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
- On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
小结:
今天有给在我后面的同学放水了呢...水题+1...
这道题目...好像没什么好说的...
以下是AC代码:
#include<stdio.h>
#include<string.h>
int chase[3100],value;
void init()
{
for(int i=0;i<=3000;i++)
chase[i]=0;
}
int main()
{
int nitem,temp1,temp2,maxd,ans;
while(~scanf("%d%d",&nitem,&value))
{
init();
maxd=0;
ans=0;
for(int i=1;i<=nitem;i++)
{
scanf("%d%d",&temp1,&temp2);
chase[temp1]+=temp2;
maxd=temp1>maxd?temp1:maxd;
}
for(int i=1;i<=maxd+1;i++)
{
int temp=value;
for(int j=i-1;j<=i;j++)
{
if(chase[j]<=temp)
{
temp-=chase[j];
ans+=chase[j];
chase[j]=0;
}
else
{
chase[j]-=temp;
ans+=temp;
temp=0;
}
}
}
printf("%d\n",ans);
}
return 0;
}
- A - Valera and Fruits
- Valera and Fruits
- codeforces-Valera and Fruits
- B. Valera and Fruits
- Codeforces Valera and Fruits
- codeforce44B. Valera and Fruits
- codeforces252-B - Valera and Fruits
- Codeforces 441 B. Valera and Fruits
- CodeForces 441B Valera and Fruits
- codeforces-441B-Valera and Fruits【暴力】
- CF #252 div2 B - Valera and Fruits
- CodeForces - 441B -Valera and Fruits
- A. Valera and Plates
- A. Valera and X
- A. Valera and X
- A. Valera and X
- Codeforces #252 (Div. 2) B. Valera and Fruits
- Codeforces Round #252 (Div. 2) 441B. Valera and Fruits
- linux学习笔记--基本命令的学习--目录处理命令
- BestCoder-Round#33
- MySQL 数据库备份种类以及常用备份工具汇总
- 机器学习算法中如何选取超参数:学习速率、正则项系数、minibatch size
- 写在23岁这一天
- A - Valera and Fruits
- 主流数据库书籍电子版下载汇总贴(84本)
- 【Android API Demos】API Demo 初探
- jvm参数设置
- 听云应用性能大讲堂
- Struts2 系统学习笔记一
- grep只打印匹配的数据
- c简单实现爬取网页
- c和c++的一些训练题(6)(杨辉三角)