AcWing 3769. 移动石子
原题链接
简单
作者:
ckyanos
,
2021-07-17 14:02:30
,
所有人可见
,
阅读 247
#include<cstdio>
const int N = 1e3;
int T;
int n, d, cost, top, cnt;
int a[N];
inline void solve() {
if(cost == d) {
printf("%d\n", cnt);
return;
}
while(cost > d) {
cost -= top;
cnt--;
}
printf("%d\n", cnt);
return;
}
int main() {
scanf("%d", &T);
while(T--) {
scanf("%d %d", &n, &d);
cost = 0, top = 0, cnt = 0;
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
if(cost < d) {
cost += a[i] * (i - 1);
cnt += a[i];
top = i - 1;
}
}
solve();
}
}