Codeforces Round #252 (Div. 2) B. Valera and Fruits
#include <iostream>
#include <vector>
#include <algorithm>
#include <map> using namespace std; int main(){
int n,v;
cin >> n >>v;
map<int,int> fruit;
for(int i = ; i < n; ++ i ){
int a,b;
cin >>a >> b;
if(fruit.find(a)!=fruit.end()) fruit[a]+=b;
else fruit.insert(make_pair(a,b));
} int pre_a = , left_b = , collect_fruit = ;
for(map<int,int>::iterator iter = fruit.begin(); iter!=fruit.end(); ++ iter){
if(iter->first - pre_a > ){
collect_fruit += (left_b > v)? v : left_b;
left_b = ;
}
if(left_b >= v){
collect_fruit +=v;
left_b = iter->second;
}else{
collect_fruit +=left_b;
if(iter->second >= (v-left_b)){
collect_fruit +=v-left_b;
left_b = iter->second-v+left_b;
}else{
collect_fruit += iter->second;
left_b = ;
}
}
pre_a = iter->first;
}
collect_fruit+=(left_b > v) ? v : left_b;
cout<<collect_fruit<<endl;
}
Codeforces Round #252 (Div. 2) B. 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 Round #252 (Div. 2) 441B. Valera and Fruits
英语不好就是坑啊.这道题把我坑残了啊.5次WA一次被HACK.第二题得分就比第一题高10分啊. 以后一定要加强英语的学习,要不然就跪了. 题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的 ...
- codeforces Round #252 (Div. 2) C - Valera and Tubes
贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...
- Codeforces Round #252 (Div. 2) A - Valera and Antique Items
水题 #include <iostream> #include <set> #include <vector> #include <algorithm> ...
- Codeforces Round 252 (Div. 2)
layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- [Codeforces Round #237 (Div. 2)] A. Valera and X
A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #216 (Div. 2) D. Valera and Fools
题目链接:http://codeforces.com/contest/369/problem/D 注意题意:所有fools都向编号最小的fool开枪:但每个fool都不会笨到想自己开枪,所以编号最小的 ...
- Codeforces Round #252 (Div. 2) D
http://codeforces.com/problemset/problem/441/D 置换群的基本问题,一个轮换内交换成正常顺序需要k-1次,k为轮换内元素个数 两个轮换之间交换元素,可以把两 ...
- Codeforces Round #216 (Div. 2) B. Valera and Contest
#include <iostream> #include <algorithm> #include <vector> using namespace std; in ...
随机推荐
- php 投票系统练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【翻译十三】java-并发之饥饿与活锁
Starvation and Livelock Starvation and livelock are much less common a problem than deadlock, but ar ...
- Linux环境下使用perl编写CGI(httpd)
例子1: /var/www/cgi-bin/hello.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print ...
- Windows 历史
- x264 - 高品质 H.264 编码器
转自:http://www.5i01.cn/topicdetail.php?f=510&t=3735840&r=18&last=48592660 H.264 / MPEG-4 ...
- 在windows系统的文件右键菜单中增加“命令提示符”
本实用小工具能够在windows系统的文件右键菜单中增加“命令提示符”,方便快速进入制定文件的命令提示窗口,避免逐层输入或复制文件夹路径,极其实用. 工具下载地址如下:360云盘(访问密码:5b71) ...
- python最简单的http服务器
人生苦短,我用python 今天有个需求就是简单的把自己的图片通过web共享,自然就想起了使用服务器了,在python下使用一个简单的服务器是非常方便的,用到标准库里面的SimpleHTTPServe ...
- objective-c 遍历文件夹查看文件
#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ @autoreleasepool ...
- CF735C 数论\平衡树叶子节点的最大深度\贪心\斐波那契\条件归一化
http://codeforces.com/problemset/problem/735/C 题意..采用淘汰赛制..只要打输就退出比赛..而且只有两个选手打过的场数 相差不超过1才能比赛..最后问你 ...
- Angular JS学习之表达式
1.Angular JS使用表达式把数据绑定到HTML: 2.Angular JS表达式写在双大括号中:{{expression}} **Angular JS表达式把数据绑定到HTML,这与ng-bi ...