Valera and Fruits
1 second
256 megabytes
standard input
standard output
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 3
1 5
2 3
8
5 10
3 20
2 20
1 20
4 20
5 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.
题目比較简单,但有两个easy忽略的地方,代码中已经标注了。
#include <iostream>
#include <cstdio>
using namespace std;
int t[3333];
int main()
{
int n,v,m,i,j,a,b;
cin>>n>>v;
int minn=9999,maxx=-1;
for(i=0;i<n;i++)
{
scanf("%d %d",&a,&b);
t[a]+=b;//可能多棵树在同一天成熟
maxx=max(maxx,a);
minn=min(minn,a);
}
int sum=0,tmp=0; for(i=minn;i<=maxx+1;i++)
{
if(tmp>=v)
{
tmp=t[i];
sum+=v;
}
else
{
if(tmp+t[i]<=v)
{ sum+=tmp+t[i];
tmp=0;//这里tmp位置非常重要,之前放在sum前面,就悲剧了
}
else
{
tmp=t[i]-(v-tmp);
sum+=v;
}
}
// cout<<tmp<<" "<<sum<<endl;
}
cout<<sum<<endl;
return 0;
}
Valera and Fruits的更多相关文章
- Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)
B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 441 B. Valera and Fruits
B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...
- C - Valera and Fruits
Problem description Valera loves his garden, where n fruit trees grow. This year he will enjoy a gre ...
- codeforces 441B. Valera and Fruits 解题报告
题目链接:http://codeforces.com/problemset/problem/441/B 题目意思:有 n 棵fruit trees,每课水果树有两个参数描述:水果成熟的时间和这棵树上水 ...
- Codeforces Round #252 (Div. 2) B. Valera and Fruits
#include <iostream> #include <vector> #include <algorithm> #include <map> us ...
- Codeforces #252 (Div. 2) B. Valera and Fruits
题目倒是不难,可是读起来非常恶心 依据题目的描写叙述不easy找到适合存储的方法 后来我就想不跟着出题人的思路走 我自己开一个数组c 令c[a[i]] = b[i] 则c[i] == [j] 代表第i ...
- Codeforces Round #252 (Div. 2) 441B. Valera and Fruits
英语不好就是坑啊.这道题把我坑残了啊.5次WA一次被HACK.第二题得分就比第一题高10分啊. 以后一定要加强英语的学习,要不然就跪了. 题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的 ...
- Codeforces441B_Valera and Fruits(暴力)
Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round 252 (Div. 2)
layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...
随机推荐
- {%csrf_token%}的作用
<form> {%csrf_token%} </form> 在django中我们需要在templates的form中加入{%csrf_token%}这串内容,它的作用是当我们g ...
- 将table导出为excel格式文件
html: <table cellpadding="0" cellspacing="0" class="data_table" id= ...
- ireport报表,打印时,报表加载失败的解决方法
1.报表加载失败图示 2.解决方法 原创作者:DSHORE 作者主页:http://www.cnblogs.com/dshore123/ 原文出自:http://www.cnblogs.com/dsh ...
- BootStrap的栅格系统的基本写法(布局)
代码如下: <!DOCTYPE html> <html> <head> <title>BootStrap的基础入门</title> < ...
- html 简单学习
通过记事本,依照以下四步来创建您的第一张网页. 步骤一:启动记事本 如何启动记事本: 开始 所有程序 附件 记事本 步骤二:用记事本来编辑 HTML 在记事本 ...
- 数据分析python应用到的ggplot
数据分析中应用到python中的ggplot库,可以用来画图 数据之类的用优达学院中课程七中的数据为例 数据是:https://s3.amazonaws.com/content.udacity-dat ...
- [BZOJ3150][Ctsc2013]猴子 期望dp+高斯消元
3150: [Ctsc2013]猴子 Time Limit: 20 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 163 Solved: 10 ...
- Java常用工具类之Excel导出
package com.wazn.learn.util; import java.util.List; import java.util.Map; import org.apache.poi.hssf ...
- 外行人都能看懂的SpringCloud
一.前言 只有光头才能变强 认识我的朋友可能都知道我这阵子去实习啦,去的公司说是用SpringCloud(但我觉得使用的力度并不大啊~~)... 所以,这篇主要来讲讲SpringCloud的一些基础的 ...
- RxSwift 系列(九)
前言 看完本系列前面几篇之后,估计大家也还是有点懵逼,本系列前八篇也都是参考RxSwift官方文档和一些概念做的解读.上几篇文章概念性的东西有点多,一时也是很难全部记住,大家脑子里面知道有这么个概念就 ...