Codeforces Round 974 (Div. 3)

A. Robin Helps

题意:

Robin一开始的钱为0, 每个人都有ai个金币, 如果ai >= k则Robin会拿着它的金币,  如果ai == 0且手上有金币,Robin会送出1金币, 输出Robin送了几次

思路:

按照题意

Code:

#include <bits/stdc++.h>
    
using namespace std;
using LL = long long;
using i64 = int64_t; 

void solve() {
    int n, k;
    cin >> n >> k;
    int ans = 0, cnt = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x >= k) {
            ans += x;
        } else if (x == 0 && ans > 0) {
            ans --;
            cnt++;
        }
    }
    cout << cnt << endl;
}

int main() {
    cin.tie(0) -> sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

  

总结:

A B C F E D H G

posted @ 2024-09-22 11:10  Iter-moon  阅读(43)  评论(0)    收藏  举报