Codeforces Round #673 (Div. 2) A. Copy-paste(贪心)

题目链接:https://codeforces.com/contest/1417/problem/A

题意

给出一个大小为 $n$ 的数组 $a$,每次操作可以选择两个数,然后将一个数加到另一个数上,要求操作后的数不能大于 $k$,问最多可以操作多少次。

题解

除一个最小值外,给每个数一直加最小值。

证明

操作的本质是留下哪一个数,明显留下较小的数更优。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        int mi = INT_MAX;
        for (auto &x : a) {
            cin >> x;
            mi = min(mi, x);
        }
        int ans = 0;
        bool skip = false;
        for (auto x : a) {
            if (x == mi and not skip) {
                skip = true;
                continue;
            }
            ans += (k - x) / mi;
        }
        cout << ans << "\n";
    }
    return 0;
}

 

posted @ 2020-09-29 13:20  Kanoon  阅读(183)  评论(0编辑  收藏  举报