Codeforces Round #355 (Div. 2)-A
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively.
The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person.
Print a single integer — the minimum possible valid width of the road.
3 7
4 5 14
4
6 1
1 1 1 1 1 1
6
6 5
7 6 8 9 10 5
11
In the first sample, only person number 3 must bend down, so the required width is equal to1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
题意:有N人,还有一个高度,每个人不能超过这个高度H。每个人通过这个高度可以有2种方式,1是当高度低于H时,这个人的宽度占1个单位,2是当高度超过H时,这个人要弯腰通过,这个人占2个单位。问最少的宽度是多少?
思路:很明显,当a[i]<=H时,对答案的贡献是1,否则对答案的贡献是2.
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
typedef long long int LL;
#define INF 0x3f3f3f3f
const int MAXN = +;
int H[MAXN];
int main(){
int n, h;
while (~scanf("%d%d", &n, &h)){
int ans = ;
for (int i = ; i < n; i++){
scanf("%d", &H[i]);
if (H[i]>h){
ans += ;
}
else{
ans += ;
}
}
printf("%d\n", ans);
}
return ;
}
Codeforces Round #355 (Div. 2)-A的更多相关文章
- Codeforces Round #355 (Div. 2)-C
C. Vanya and Label 题目链接:http://codeforces.com/contest/677/problem/C While walking down the street Va ...
- Codeforces Round #355 (Div. 2)-B
B. Vanya and Food Processor 题目链接:http://codeforces.com/contest/677/problem/B Vanya smashes potato in ...
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure dp+分块
题目链接: http://codeforces.com/contest/677/problem/D 题意: 让你求最短的从start->...->1->...->2->. ...
- E. Vanya and Balloons Codeforces Round #355 (Div. 2)
http://codeforces.com/contest/677/problem/E 题意:有n*n矩形,每个格子有一个值(0.1.2.3),你可以在矩形里画一个十字(‘+’形或‘x’形),十字的四 ...
- D. Vanya and Treasure Codeforces Round #355 (Div. 2)
http://codeforces.com/contest/677/problem/D 建颗新树,节点元素包含r.c.dis,第i层包含拥有编号为i的钥匙的所有节点.用i-1层更新i层,逐层更新到底层 ...
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure 分治暴力
D. Vanya and Treasure 题目连接: http://www.codeforces.com/contest/677/problem/D Description Vanya is in ...
- Codeforces Round #355 (Div. 2) C. Vanya and Label 水题
C. Vanya and Label 题目连接: http://www.codeforces.com/contest/677/problem/C Description While walking d ...
- Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题
B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
随机推荐
- iOS-UIView 之 layoutMargins & preservesSuperviewLayoutMargins 解惑
这里先看下苹果给出的解释: iOS8.0之后,uiview默认layoutMargins 为(8,8,8,8),也可以自己指定,仅适用于自动布局:当添加子view到父view上时,这样设置好约束 默认 ...
- shiro错误总结
今天在做spring+mybatis+springmvc+shiro的时候,报这个错,刚开始以为是shiro登录验证出错,后来,观看一下错误,发现在别的xml中写错了代码,shiro接连着报错,记录一 ...
- android入门到熟练(五)---广播
1.广播类型:标准广播和有序广播.标准广播是异步广播在广播发出之后所有接收器几乎会同一时刻接收到,没有先后顺序,效率高,但无法被截断.有序广播则是同步广播,同一时刻只能一个接收器接收这条消息,等执行完 ...
- rsync使用
1)拷贝本地文件.当SRC和DES路径信息都不包含有单个冒号":"分隔符时就启动这种工作模式. 如:rsync -a ./test.c /backup 2)使用一个远程 ...
- ZendStudio如何汉化
点击工具栏的help,看图 点击 Install New Sofaware... 看图 然后.... 在地址(12.0的版本):http://download.eclipse.org/techno ...
- Java反射实战
一.背景 最近的项目中需要使用到Java 反射的知识,以前不怎么了解,也基本没怎么用过,抽出一片时间,来具体学习和实战下Java的反射!拿来和大家分享以及记录方便以后学习! 二.反射相关概念解析 1. ...
- Warp divergence
Threads are executed in warps of 32, with all threads in the warp executing the same instruction at ...
- JS判断是否为IE浏览器 包含了IE11
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...
- WebService – 3.后台调用WebService,根级别上的数据无效
1.因为我的webservice返回的是json, 2.ajax传递跨域不安全, 3.contentType: "application/json; charset=utf-8", ...
- ASP.NET MVC中ViewData、ViewBag和TempData
1.ViewData 1.1 ViewData继承了IDictionary<string, object>,因此在设置ViewData属性时,传入key必须要字符串型别,value可以是任 ...