-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_Inhabitant_of_the_Deep_Sea.cpp
67 lines (59 loc) · 1.15 KB
/
C_Inhabitant_of_the_Deep_Sea.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
RunAt - green
*/
#include <iostream>
#include <set>
#include <climits>
#include <cmath>
#include <numeric>
#include <map>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef int long long ll;
#define p(a) cout << a << "\n";
#define p2(a,b) cout << a << " " << b << "\n";
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
const int N = 1e5+5;
const int MOD = 1e9+7;
void solve() {
ll n, k;
cin >> n >> k;
vector<long long> vec(n);
for (auto &e: vec) cin >> e;
int s=0, e=n-1;
ll boats = 0;
while (s<e) {
ll mini = min(vec[s],vec[e]);
if (k-2*mini>=0) {
vec[s] -= mini;
vec[e] -= mini;
if (vec[s] == 0) {boats++; s++;}
if (vec[e] == 0) {boats++; e--;}
k -= 2*mini;
}
else {
vec[s] -= k/2;
vec[e] -= k/2;
vec[s] -= k%2;
if (vec[s] == 0) boats++;
if (vec[e] == 0) boats++;
break;
}
if (k==0) break;
}
if (s==e && vec[s] != 0) {
if (vec[s]-k <= 0) boats++;
}
p(boats);
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int tests = 1;
cin >> tests;
while (tests--) solve();
return 0;
}