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 ...
随机推荐
- MVC基础知识 – 2.新语法
1.自动属性 Auto-Implemented Properties 2.隐式类型 var 3.参数默认值 和 命名参数 4.对象初始化器 与 集合初始化器 { } 5.匿名类 & 匿名方法 ...
- Install PIL on mac osX10.9
follow this instruction: http://blog.csdn.net/liushuaikobe/article/details/8729652 and if you encoun ...
- Solr入门之(6)配置文件solrconfig.xml
solrconfig.xml包含了用于配置自身行为的绝大部分参数,其作用范围是当前core.该文件位于${solr_home}/solr/core1/conf/下. 参数列表概览: A.lib B.d ...
- wp8 入门到精通 Animation 背景加字体颜色从下向上变化颜色效果
<phone:PhoneApplicationPage.Resources> <Style x:Key="ButtonStyle1" TargetType=&qu ...
- hdu 4762 公式 java
n/(n)^(m-1) import java.io.*; import java.math.*; import java.util.*; public class Main { static Big ...
- [Oracle] PL/SQL学习笔记
-- 1. 使用一个变量 declare -- Local variables here v_name ); begin -- Test statements here select t.user_n ...
- 修改Apache配置文件开启gzip压缩传输
转自:http://down.chinaz.com/server/201202/1645_1.htm 最近无事研究一些Web的优化,用工具page speed检测网站时发现还没有开启gzip压缩,于是 ...
- 实现Activity刷新 (转)
目前刷新Acitivity,只想到几种方法.仅供参考,如果您有更好的方法,请赐教. 程序界面: 点击refresh view可以刷新界面,点击write content可以在EditText中自动写入 ...
- 在Asp.Net MVC中设定site路径所对应的默认action
设置路由的default的Controller和Action可以达到我们预期的效果,代码如下所示: public class RouteConfig { public static void Regi ...
- POJ 1830 高斯消元
开关问题 Description 有N个相同的开关,每个开关都与某些开关有着联系,每当你打开或者关闭某个开关的时候,其他的与此开关相关联的开关也会相应地发生变化,即这些相联系的开关的状态如果原来为 ...