Codeforces 789A Anastasia and pebbles( 水 )


**链接:****传送门 **

题意:这个人每次都去公园捡石子,她有两个口袋,每个口袋最多装 k 个石子,公园有 n 种石子,每种石子 w[i] 个,询问最少几天能将石子全部捡完

思路:排个序,尽量每天都多装,如果 k > w[i] ,那就直接将石子全部放入口袋,如果 k < w[i] 那就多次来装。


/*************************************************************************
> File Name: Codeforces789A.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月25日 星期四 10时43分22秒
************************************************************************/

include<bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5 + 10;
int w[MAX_N] , n , k;

bool cmp(int a,int b){
return a>b;
}
int main(){
while(~scanf("%d%d",&n,&k)){
for(int i = 0 ; i < n ; i++) scanf("%d",&w[i]);
sort( w , w + n , cmp );
int ans = 0;
for(int i = 0 ; i < n ; i++){
if( w[i] % k == 0 ) ans += w[i]/k;
else ans += w[i]/k + 1;
}
if( !(ans&1) ) ans /= 2;
else ans = ans/2 + 1;
printf("%d\n",ans);
}
return 0;
}

posted @ 2017-05-25 11:07  ojnQ  阅读(232)  评论(0)    收藏  举报