Codeforces441B_Valera and Fruits(暴力)
来源:互联网 发布:javascript函数传值 编辑:程序博客网 时间:2024/06/03 12:21
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?
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.
Print a single integer — the maximum number of fruit that Valera can collect.
2 31 52 3
8
5 103 202 201 204 205 20
60
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.
解题报告
这题好像就是暴力。从第一天开始,取最大的收获量就是。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int n,v;struct node{ int t,d;} num[10000];int cmp(node a,node b){ return a.t<b.t;}int main(){ int i,j; while(cin>>n>>v) { int sum=0; for(i=0; i<n; i++) cin>>num[i].t>>num[i].d; sort(num,num+n,cmp); for(i=1; i<=3001; i++) { int vv=v; for(j=0; j<n; j++) { if(i-num[j].t<=1&&i-num[j].t>=0) { if(num[j].d>=vv) { sum+=vv; num[j].d-=vv; break; } else { vv-=num[j].d; sum+=num[j].d; num[j].d=0; } } } } printf("%d\n",sum); } return 0;}
- Codeforces441B_Valera and Fruits(暴力)
- codeforces-441B-Valera and Fruits【暴力】
- Valera and Fruits
- codeforces-Valera and Fruits
- B. Valera and Fruits
- Codeforces Valera and Fruits
- A - Valera and Fruits
- codeforce44B. Valera and Fruits
- codeforces252-B - Valera and Fruits
- 线性石子归并JOJ2521: Monkey and fruits
- Codeforces 441 B. Valera and Fruits
- CodeForces 441B Valera and Fruits
- CF #252 div2 B - Valera and Fruits
- CodeForces - 441B -Valera and Fruits
- Codeforces #252 (Div. 2) B. Valera and Fruits
- Codeforces Round #252 (Div. 2) 441B. Valera and Fruits
- Codeforces Round #252 (Div. 2)B. Valera and Fruits
- Codeforces Round #252 (Div. 2)-B. Valera and Fruits
- 基于Raphael的流程设计器,前台部分
- cocos2dx3.1中,在lua脚本中导入cocostudio UI编辑器的布局
- Dede后台验证码不显示解决方法详解(dedecms 5.7)
- Android开发之ImageSwitcher组件的使用以及设置图片切换的效果
- POJ 2240 HDU 1217 Arbitrage
- Codeforces441B_Valera and Fruits(暴力)
- 第117天
- 利用nginx搭建http和rtmp协议的流媒体服务器
- matlab练习程序(图像旋转,双线性插值)
- OCP 1Z0 053 3
- 编写一个真正可以用的makefile,遇到的问题及特殊符号含义汇总
- OpenGL ES 2.0 Shader相关介绍
- mac下一些mysql数据库的操作
- hdu 3177贪心