-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPREFONES.cpp
More file actions
112 lines (106 loc) · 2.49 KB
/
Copy pathPREFONES.cpp
File metadata and controls
112 lines (106 loc) · 2.49 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
///*Bismillahir Rahmanir Rahim***///
///**Author thasin_sheikh**///
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using myset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
#define MAX 1e6+10
#define MOD 1000000007
#define PI acos(-1)
#define R 510
#define makefast__ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using ll=long long int ;
using dl =double;
using ld=long double;
using ull=unsigned long long;
const long N = 3e5 + 10;
const long maxn=5e5+10;
const long long maxval=1e18;
const long long minval=-1e18;
typedef tree<ll ,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>os;
ll aarray[N];
ll magic[R][R];
vector<ll>primes;
//bool check[1000001];
//ll large[10000005];
//int dx[] = {-1 , 0 , 1 , 0};
//int dy[] = {0 , 1 , 0 , -1};
/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction
ll vis[N];
vector<ll>ed[N];
map<ll,ll>mp;
//priority_queue<ll>pq;// from max to min
void solve()
{
ll i,j,k,m,n,l,r,q,p,ans,sum=0,a,b,c,d,mi=maxval,ma=minval;
string str;
bool yes=true;
vector<ll>v;
cin>>n;
cin>>str;
ans=0;
for(i=0;i<n;i++)
{
if(str[i]=='1')
{
sum++;
ans=max(ans,sum);
}
else
{
v.push_back(sum);
sum=0;
}
if(i==n-1&&str[i]=='1')
{
v.push_back(sum);
ans=max(ans,sum);
}
}
if(str[0]=='0')
{
cout<<ans<<"\n";
return ;
}
if(v.size()==0)
{
cout<<0<<"\n";
return ;
}
else if(v.size()==1)
{
cout<<v[0]<<"\n";
return ;
}
else
{
for(i=1;i<v.size();i++)
{
ma=max(ma,v[i]);
}
cout<<v[0]+ma<<"\n";
}
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//tle khaite chas to endl use kor
//check test case in interactive , idiot
//never use pow func directly
//add and subtract
makefast__
string str;
ll i,j,n,m,k,t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}