链接

A. Anastasia and pebbles

题意

这个人有两个口袋,有n种类型的鹅卵石,每种鹅卵石有wi个,每次可以放同一种最多k个,每次不能把不同类型的鹅卵石放进同一个口袋,但是她可以同时把不同种类的鹅卵石放在不同的口袋里,一天只能收集一次,问收集完所有的鹅卵石需要多少天

做法

我们只需要计算出每种类型需要多少次装进袋子里,即codeforces 789 A. Anastasia and pebbles ,然后由于有两个袋子,所以codeforces 789 A. Anastasia and pebbles,考虑到不能整除的情况,所以要对结果向上取整,复杂度O(n)。

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100010;
int main() {
    int n,k;
    cin>>n>>k;
    int w[maxn];
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>w[i];
        sum+=w[i]/k+(w[i]%k>0);
    }
    cout<<(sum/2+(sum%2>0))<<endl;
    return 0;
}

相关文章:

  • 2022-01-20
  • 2021-12-31
  • 2021-08-31
  • 2021-11-02
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2021-08-29
  • 2022-03-03
  • 2021-05-21
  • 2021-12-31
相关资源
相似解决方案