-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_deque.cpp
54 lines (48 loc) · 1.12 KB
/
binary_deque.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
/* Author Ahmed Anwar
* Problem Link https://codeforces.com/contest/1692/problem/E
*/
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef signed long long sll;
int main()
{
int t;// = 1;
cin >> t;
while (t--) {
vector<int> queue;
int n, s;
cin >> n >> s;
unsigned long long sum = 0;
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
queue.push_back(tmp);
sum += tmp;
}
if (sum < s) {
cout << -1 << endl;
continue;
}
else if (sum == s) {
cout << 0 << endl;
continue;
}
int curr_sum = 0;
int ans = -1;
for (int r = 0, l = 0; l < n; ++l) {
if (l > r) {
r = l;
curr_sum = 0;
}
while (r < n && curr_sum + queue[r] <= s) {
curr_sum += queue[r];
r++;
}
ans = max(r-l, ans);
curr_sum -= queue[l];
}
cout << n - ans << endl;
}
return 0;
}