-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF1955C.cpp
36 lines (36 loc) · 948 Bytes
/
CF1955C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t T;
cin >> T;
while (T--) {
size_t n;
uli k;
cin >> n >> k;
deque<ui> a(n);
for (ui& i : a) cin >> i;
while (a.size() > 1 && k > 1) {
ui d = min(a.front(), a.back());
if (d * 2 > k) d = k / 2;
a.front() -= d, a.back() -= d, k -= d * 2;
if (!a.empty() && a.front() == 0) a.pop_front();
if (!a.empty() && a.back() == 0) a.pop_back();
}
if (a.size() == 1) {
ui d = min<uli>(a.front(), k);
a.front() -= d, k -= d;
if (!a.empty() && a.front() == 0) a.pop_front();
}
if (k && !a.empty()) {
--a.front();
if (a.front() == 0) a.pop_front();
}
cout << n - a.size() << '\n';
}
return 0;
}