-
Notifications
You must be signed in to change notification settings - Fork 0
/
E.cpp
46 lines (44 loc) · 864 Bytes
/
E.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
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int ara[200005];
int main()
{
fastio;
int t,n,s,i,on,l,r,mn;
cin>>t;
while(t--)
{
cin>>n>>s;
mn=300000;
vector<int> pos;
for(i=0;i<n;i++)
{
cin>>ara[i];
if(ara[i]==1)
pos.push_back(i);
}
if(pos.size()<s)
{
cout<<-1<<"\n";
continue;
}
on=pos.size();
for(i=0;i<=on-s;i++)
{
if(i==0)
{
l=0;
}
else
l=pos[i-1]+1;
if(i+s-1==on-1)
r=n-1;
else
r=pos[i+s]-1;
mn=min(mn,l+n-1-r);
}
cout<<mn<<"\n";
}
return 0;
}