it’s an easy problem. the logic behind this problem is to count number of goals for both team after every shootout and when one of them has no more chance to shoot goals and compensate the difference in goals of two team.

for example

let there are 6 total penalty shootout

after 4 penalty shootout team A do 4 goals and team B do 0 goal now both team has to more chances to shoot but even then B cant compensate the difference between the goals and lose the match so at 4 we know which team wins in advance so answer is 4.

this is code for problem

```
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
string s;
int n;
cin>>n;
cin>>s;
int a=0,b=0,c=0;
int counta=0,countb=0;
for(int j =0;j<2*n;j++)
{
if(j%2==0)
{ counta++;
if(s[j]=='1')
{a++;}
}
else if(j%2!=0)
{countb++;
if(s[j]=='1')
{b++;}
}
if(a-b>n-countb)
{cout<<j+1<<endl;
c=1;
break;
}
if(b-a>n-counta)
{cout<<j+1<<endl;
c = 1;
break;
}
}
if(c==0)
{cout<<2*n<<endl;}
}
return 0;
}
```

6 Likes

for _ in range(int(input())):

n=int(input())

a=list(map(int,input()))

diff=0

s=0

for i in range(0,len(a),2):

diff+=a[i]-a[i+1]

s+=1

if(diff>n//2):

break

print(s*2)

can anyone tellme where it’s wrong

The problem with your code might be is that in some cases it doesn’t look at B’s score and gives an output ‘n’ instead on n + 1 .

while there are some cases that don’t require you to look at B’s outcome after a point.

Another problem might be is your output is 2s and s being an int, the ans has to be an even number , which is incorrect. consider this case - ( n = 5 ) 1 0 1 0 1 1 0 1 0 . The output is determined at 5 which in your case would result in WA. For extra help here is my submission -[CodeChef: Practical coding for everyone .](CodeChef: Practical coding for everyone .)

1 Like

got it the number should be the point where the score above that doesn’t matter

1 Like

Can anyone please tell me what is wrong with this code?

```
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll t;
cin>>t;
while(t--){
ll n, a=0, b=0,ind=0;
cin>>n;
string s;
cin>>s;
ind=0;
for(ll i=0;i<2*n;i++){
if(i%2==0){
a+=s[i]-'0';
ind+=1;
}
else{
b+=s[i]-'0';
if(ind>int(n/2)){
if(a!=b && ((a>b && a-b>n-ind) || (b>a && b-a>n-ind))){
cout<<i+1<<"\n";
break;
}
else if(ind==n){
cout<<i+1<<"\n";
break;
}
}
}
}
}
return 0;
}
```

```
PLEASE tell what is wrong in my code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
string s;
int n;
cin>>n;
cin>>s;
int a=0,b=0,c=0;
int counta=0,countb=0;
for(int j =0;j<2*n;j++)
{
if(j%2==0)
{ counta++;
if(s[j]=='1')
{a++;}
}
else if(j%2!=0)
{countb++;
if(s[j]=='1')
{b++;}
}
if(a-b>n-countb)
{cout<<j+1<<endl;
c=1;
break;
}
if(b-a>n-counta)
{cout<<j+1<<endl;
c = 1;
break;
}
}
if(c==0)
{cout<<2*n<<endl;}
}
return 0;
}
```

Please tell me where I am lacking

#include

#include

#include

using namespace std;

int main()

{

```
short cases;
cin>>cases;
while(cases--)
{
int teamA=0,teamB=0;
int NumberOfShots,i,maximum;
cin>>NumberOfShots;
string shots;
cin>>shots;
for(i=0;i<2*NumberOfShots;i++)
{
if(i%2==0)
teamA+=shots[i]-'0';
else
teamB+=shots[i]-'0';
maximum=max(teamA,teamB);
if(i%2!=0&&maximum>NumberOfShots/2)
{
if((teamA-teamB)>(NumberOfShots-maximum)||(teamB-teamA)>(NumberOfShots-maximum))
{
i++;
break;}
}
}
cout<<i<<"\n";
}
return 0;
```

}