Codeforces Round #355 (Div. 2)

原创 2016年06月02日 07:24:26

Codeforces Round #355 (Div. 2)


A. Vanya and Fence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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?

Input

The first line of the input contains two integers n and h (1 ≤ n ≤ 10001 ≤ 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.

Output

Print a single integer — the minimum possible valid width of the road.

Examples
input
3 7
4 5 14
output
4
input
6 1
1 1 1 1 1 1
output
6
input
6 5
7 6 8 9 10 5
output
11
Note

In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.

In the second sample, all friends are short enough and no one has to bend, so the width 1 + 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 to2 + 2 + 2 + 2 + 2 + 1 = 11.


#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n,lim;
    while(scanf("%d%d",&n,&lim)!=EOF){
        int ans=0;
        while(n--){
            int tall;
            scanf("%d",&tall);
            if(tall>lim)
                ans+=2;
            else
                ans++;
        }
        printf("%d\n",ans);
    }
}


B. Vanya and Food Processor
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed hand the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than during this second processor smashes all the remaining potato.

Vanya has n pieces of potato, the height of the i-th piece is equal to ai. He puts them in the food processor one by one starting from the piece number 1 and finishing with piece number n. Formally, each second the following happens:

  1. If there is at least one piece of potato remaining, Vanya puts them in the processor one by one, until there is not enough space for the next piece.
  2. Processor smashes k centimeters of potato (or just everything that is inside).

Provided the information about the parameter of the food processor and the size of each potato in a row, compute how long will it take for all the potato to become smashed.

Input

The first line of the input contains integers nh and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ h ≤ 109) — the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively.

The second line contains n integers ai (1 ≤ ai ≤ h) — the heights of the pieces.

Output

Print a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement.

Examples
input
5 6 3
5 4 3 2 1
output
5
input
5 6 3
5 5 5 5 5
output
10
input
5 6 3
1 2 1 1 1
output
2
Note

Consider the first sample.

  1. First Vanya puts the piece of potato of height 5 into processor. At the end of the second there is only amount of height 2 remaining inside.
  2. Now Vanya puts the piece of potato of height 4. At the end of the second there is amount of height 3 remaining.
  3. Vanya puts the piece of height 3 inside and again there are only 3 centimeters remaining at the end of this second.
  4. Vanya finally puts the pieces of height 2 and 1 inside. At the end of the second the height of potato in the processor is equal to 3.
  5. During this second processor finally smashes all the remaining potato and the process finishes.

In the second sample, Vanya puts the piece of height 5 inside and waits for 2 seconds while it is completely smashed. Then he repeats the same process for 4 other pieces. The total time is equal to 2·5 = 10 seconds.

In the third sample, Vanya simply puts all the potato inside the processor and waits 2 seconds.


数学问题模拟就行(加取余以节约速度)

另Codeforces的格式限制:%I64d(win),不能%lld(linux)

或着用cout加取消stdio同步ios::sync_with_stdio(false)

大数据组说明(数据时间截至2016.6.2)

test 9

45991 22981793 6964305

test 14

100000 1000000000 1

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
    long long n,lim,cut,sum,x,ans;
    while(cin>>n>>lim>>cut){
        ans=0;
        //scanf("%d",&sum);
        sum=0;
        scanf("%I64d",&x);
        long long i=1;
        while(1){
            if(sum+x>lim){
                double tim=(sum+x-lim)/(double)cut;
                long long t=(long long)ceil(tim);
                ans+=t;
                sum-=t*cut;
                if(sum<0) sum=0;
            }else{
                sum+=x;
                if(i>=n) break;
                scanf("%I64d",&x);
                i++;
            }

        }
        ans+=sum/cut;
        if(sum%cut!=0)
            ans++;
        cout<<ans<<endl;
    }
}


C. Vanya and Label
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 109 + 7.

To represent the string as a number in numeral system with base 64 Vanya uses the following rules:

  • digits from '0' to '9' correspond to integers from 0 to 9;
  • letters from 'A' to 'Z' correspond to integers from 10 to 35;
  • letters from 'a' to 'z' correspond to integers from 36 to 61;
  • letter '-' correspond to integer 62;
  • letter '_' correspond to integer 63.
Input

The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'.

Output

Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 109 + 7.

Examples
input
z
output
3
input
V_V
output
9
input
Codeforces
output
130653412
Note

For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.

In the first sample, there are 3 possible solutions:

  1. z&_ = 61&63 = 61 = z
  2. _&z = 63&61 = 61 = z
  3. z&z = 61&61 = 61 = z


这题啥意思?


版权声明:欢迎转载,请注明出处噢,谢谢

Codeforces Round #406 (Div. 2):C. Berzerk(记忆化搜索解决博弈问题)

C. Berzerk time limit per test 4 seconds memory limit per test 256 megabytes input standard in...
  • Jaihk662
  • Jaihk662
  • 2017年03月24日 15:23
  • 791

【Codeforces Round 375 (Div 2) E】【欧拉回路Fleury算法 或网络流】One-Way Reform 每条边定向使得最多的点满足入度=出度

E. One-Way Reform time limit per test 2 seconds memory limit per test 256 megabytes ...
  • snowy_smile
  • snowy_smile
  • 2016年10月04日 10:20
  • 735

数学推公式——较难——Codeforces Round #187 (Div. 2)

题目链接: http://codeforces.com/contest/315/problem/C C. Sereja and Contest time limi...
  • CS_liuqing
  • CS_liuqing
  • 2013年06月16日 15:34
  • 1995

Codeforces Round #244 (Div. 2)(强连通分量,后缀数组)

A. Police Recruits #include #include #include #include using namespace std; int n; int main() { ...
  • u010660276
  • u010660276
  • 2014年05月23日 20:08
  • 420

Codeforces Round #248 (Div. 2) B题 【数据结构:树状数组】

题目链接:http://codeforces.com/contest/433/problem/B 题目大意:给n(1 ≤ n ≤ 105)个数据(1 ≤ vi ≤ 109),其中有m(1 ≤ m ≤...
  • u013912596
  • u013912596
  • 2014年05月24日 18:18
  • 706

Codeforces Round #312 (Div. 2) (第三题是位运算,好题)

比赛:点击打开链接 558A - Lala Land and Apple Trees 分析:从0坐标分开,负半轴一个数组,正半轴一个数组,来记录果树的左边和数量,可以用结构体数组来存储数据,其...
  • loveyou11111111
  • loveyou11111111
  • 2015年08月31日 16:30
  • 156

【打CF,学算法——三星级】CodeForces 689C Mike and Chocolate Thieves (二分)

题目链接:CF 689C 题面: C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit ...
  • David_Jett
  • David_Jett
  • 2016年07月08日 10:55
  • 791

【专题】线段树

单点更新 最最基础的线段树,只更新叶子节点,然后把信息用PushUP(int r)这个函数更新上来。 hdu1166 敌兵布阵 线段树 hdu 1166 敌兵布阵 单点更新区间求和 hdu1754 ...
  • cyendra
  • cyendra
  • 2013年05月12日 17:33
  • 736

newLISP® 代码模式

newLISP® 代码模式 Version 2012 February 14th newLISP v.10.4.0 Copyright © 2012 Lutz Mueller, ...
  • gxp
  • gxp
  • 2013年12月10日 10:26
  • 1460

Codeforces Round #303 (Div. 2) E 最短路迪杰斯特拉(小根堆实现)

链接:戳这里 E. Paths and Trees time limit per test3 seconds memory limit per test256 megabytes...
  • libin66
  • libin66
  • 2016年07月22日 17:29
  • 286
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #355 (Div. 2)
举报原因:
原因补充:

(最多只允许输入30个字)