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 ...
随机推荐
- [How to] 使用HBase协处理器---Endpoint服务端的实现
1.简介 前篇文章[How to] 使用HBase协处理器---基本概念和regionObserver的简单实现中提到了两种不同的协处理器,并且实现了regionObserver. 本文将介绍如何使用 ...
- [ python ] 软件开发规范
在python开发中,我们建议采用如下规范: soft/ ├── bin # 程序执行文件目录 │ ├── __init__.py │ └── start.py # 程序开始执行脚本文件 ├─ ...
- java版云笔记(四)
页面的笔记本加载完成了,接下来就是点击笔记本显示将笔记显示,同时把笔记在右边的编辑器中,同时把编辑后的笔记更新. 注:这个项目的sql文件,需求文档,需要的html文件,jar包都可以去下载,下载地址 ...
- 修改TortoiseSVN客户端登陆用户
TortoiseSVN是一款常用且非常不错的SVN工具,俗称小乌龟.开发的时候,经常用的当然是TortoiseSVN客户端了. 一般情况下,TortoiseSVN服务器提供的IP地址和用户都不会变,而 ...
- 简易web-slide
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jvisualvm 远程连接jboss
由于项目中使用jboss 作为web容器,每当项目上线时需要使用loadrunner对项目进行性能压测,这时就需要实时观察JVM的一些参数.想使用jvisualvm借助jstatd远程连接服务器上面的 ...
- 【LOJ】 #2015. 「SCOI2016」妖怪
题解 这道题教会我很多东西,虽然它是个傻逼三分 1.long double的运算常数是巨大的 2.三分之前的界要算对!一定要算准,不要想一个直接写上! 3.三分100次也就只能把精度往里推20多位,可 ...
- 【SQL Server】书签
书签是什么 不论表是堆结构还是段结构,可以确定的是,表中每一行都是某一页的第N行,这个某一页又是某个数据库文件的第N页,这个某个数据库文件又是构成数据 库的文件组的第N个文件,因此,数据库中的每一行, ...
- 【Python初级】由生成杨辉三角代码所思考的一些问题
杨辉三角定义如下: 1 / \ 1 1 / \ / \ 1 2 1 / \ / \ / \ 1 3 3 1 / \ / \ / \ / \ 1 4 6 4 1 / \ / \ / \ / \ / \ ...
- socket的使用二
基于UDP协议的socket udp是无链接的,先启动哪一端都不会报错 简单使用 server端 import socket udp_sk = socket.socket(type=socket.SO ...