• 789A Anastasia and pebbles


    A. Anastasia and pebbles
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    Examples
    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.

     题意:有两个口袋,每个口袋只能放一种石头,共有 K 种石头, 每种分别w[i] 种

     解题思路:计算共需要多少口袋装完, (ans + 1)  / 2 即为所求

     1 #include <iostream>
     2 #define ll long long
     3 using namespace std;
     4 int main()
     5 {
     6     ll n, k;
     7     cin >> n >> k;
     8     int ans = 0;
     9     for(int i = 1;i <= n; i++)
    10     {
    11         int w;
    12         cin >> w;
    13         ans += w / k;
    14         if(w % k) ans++;
    15     }
    16     cout << (ans + 1) / 2 << endl;
    17 }

                    

  • 相关阅读:
    WSS页面定制系列(1)如何启用表单页面的编辑模式
    [转载]Customizing the Context Menu of Document Library Items
    MOSS publishing功能:创建页面到子文件夹
    CodeArt.SharePoint.CamlQuery_0.9发布(源码)
    WSS页面定制系列(2)定制单个列表的表单页面
    WSS页面定制系列(3)重写表单的保存逻辑
    MOSS字段编辑权限控制方案(3)重写表单字段呈现逻辑
    WSS(MOSS)如何修改Rich文本编辑器的宽度
    web录音的实现
    WSS 扩展文件夹的属性如何给文件夹添加扩展字段
  • 原文地址:https://www.cnblogs.com/jxust-jiege666/p/6711320.html
Copyright © 2020-2023  润新知