zoukankan      html  css  js  c++  java
  • codeforces contest 789 (div 2 )

    A. Anastasia and pebbles

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.

    She has only two pockets. She can put at most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.

    Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.

    Input

    The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.

    The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.

    Output

    The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.

    input

    3 2
    2 3 4

    output

    3

    input

    5 4
    3 1 8 9 7

    output

    5

    Note

    In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.

    Optimal sequence of actions in the second sample case:

    • In the first day Anastasia collects 8 pebbles of the third type.
    • In the second day she collects 8 pebbles of the fourth type.
    • In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type.
    • In the fourth day she collects 7 pebbles of the fifth type.
    • In the fifth day she collects 1 pebble of the second type.

     Solution

    大水题,然而我WA了好几次....都是提交框的错qwq

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 using namespace std;
     6 int n,k,ans;
     7 int main()
     8 {
     9     scanf("%d%d",&n,&k);
    10     for(int i=1,w;i<=n;i++)
    11     {
    12         scanf("%d",&w);
    13         ans+=w/k;
    14         if(w%k!=0) ans++;
    15     }
    16     printf("%d
    ",ans/2+(ans%2));
    17     return 0;
    18 } 
    View Code
  • 相关阅读:
    MOSS 2010 修改管理员密码 欧阳锋
    MOSS2010 中“找不到位于xxxx的web应用程序”的解决办法 欧阳锋
    MSSQL 2008 无法修改表问题的解决 欧阳锋
    不是每个在你身上拉屎的都是你的敌人 欧阳锋
    笑一笑 欧阳锋
    隐藏MOSS2010 左边的导航 欧阳锋
    爱情与婚姻的区别 欧阳锋
    两年后,我们怎么办
    C#控件的闪烁问题解决方法总结
    Linux内核编译配置过程
  • 原文地址:https://www.cnblogs.com/juruohx/p/7603041.html
Copyright © 2011-2022 走看看