Untitled
unknown
plain_text
2 years ago
956 B
13
Indexable
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
const double PI = 3.14159265358979;
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;
const ll nax = 1000005;
const int LOG = 25;
void solve() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int zeroCnt = 0, tail = 0, head = -1, ans = 0;
while(tail < n) {
while(head + 1 < n && ((a[head + 1] == 0) + zeroCnt) <= k) {
head++;
zeroCnt += (a[head] == 0);
}
ans = max(ans, head - tail + 1);
if (head >= tail) {
zeroCnt -= (a[tail] == 0);
tail++;
} else {
tail++;
head = tail - 1;
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t; cin >> t; while(t--)
solve();
return 0;
}Editor is loading...
Leave a Comment