Loading

Codeforces Round #694 (Div. 2) A. Strange Partition

题目链接

题目分析

题意:给一个数组,允许其中相邻的两个元素相加合并,问合并的不同种情况中,每个元素除以x向上取整之后的和的最小值和最大值是多少

通过题目所给的数据会发现,当不执行任何合并操作后的和为最大值,数组元素之和除以x向上取整为最小值。(这个自己写写算算就能够发现的)

AC代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t, n, x;
ll p;
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> t;
    while(t--){
        long long minn = 0, maxn = 0;
        cin >> n >> x;
        for(int w = 0; w < n; w++){
            cin >> p;
            minn += p;
            maxn += ceil(x * 0.1 / x);
        }
        minn = ceil(minn * 0.1 / x);
        cout << minn << ' ' << maxn << endl;
    }
    
    return 0;
}
posted @ 2021-01-06 01:20  Frank_Ou  阅读(47)  评论(0编辑  收藏  举报