【題解】Codeforces 1307A. Cow and Haybales

【題目敘述】http://codeforces.com/contest/1307/problem/A

#include <iostream>
using namespace std;
 
int t, n, d, a, ans, add;
 
int main() {
    cin >> t;
    while (t--){
        cin >> n >> d;
        cin >> a;
        ans = a;
        for (int i = 1; i < n; i++){
            cin >> a;
            add = min(a, d/i);
            ans += add;
            d -= add*i;
        }
        cout << ans << "\n";
    }
}
分享本文 Share with friends