PENALTY - Editorial

PROBLEM LINK:

Practice
Contest: Division 3
Contest: Division 2
Contest: Division 1

Author: Daanish Mahajan
Tester : Radoslav Dimitrov
Editorialist: Aman Dwivedi

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Given ten integers A_1, A_2, \ldots, A_{10}, where the odd indexed integers(A_1, A_3, A_5, A_7, A_9) represent the outcome of the shots made by team 1 and even indexed integers(A_2, A_4, A_6, A_8, A_{10}) represent the outcome of the shots made by team 2 (here A_i = 1 indicates that it’s a goal and A_i = 0 indicates a miss), determine the winner or find if the game ends in a draw.

EXPLANATION:

We can simply count the number of goals for each team and then we can easily determine the winner (or the game ends in a draw).

How to count the number of goals for each team?

  • Simply do as the problem statement says. If the shot number is odd and there is a goal in this shot we can increment the count of goals of Team 1.

  • Similarly, if the shot number is even and there is a goal in this shot we can increment the count of goals of Team 2.

Finally, check which team has more goals and output that team. If the number of goals is the same output 0 which means the game ended in a draw.

TIME COMPLEXITY:

O(1) per test case

SOLUTIONS:

Author
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define rb pop_back
#define ti tuple<int, int, int>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define mp make_pair
#define mt make_tuple

using namespace std;
  
const int maxt = 1024;
const string newln = "\n", space = " ";

int main()
{   
    int t; cin >> t;
    while(t--){
        int c[2]; c[0] = c[1] = 0;
        for(int i = 0; i < 10; i++){
            int x; cin >> x;
            c[i & 1] += x;
        }
        int ans = 0;
        if(c[0] > c[1])ans = 1;
        else if(c[0] < c[1]) ans = 2;
        cout << ans << endl;
    }
} 
Tester
def solve_case():
    x = [int(x) for x in input().split()]
    
    balanace = 0
    for i, x in enumerate(x):
        if i & 1: 
            balanace += x
        else:
            balanace -= x
    
    if balanace == 0:
        print(0)
    elif balanace < 0:
        print(1)
    else:
        print(2)


cases = int(input())
for _ in range(cases):
    solve_case()

Editorialist
#include<bits/stdc++.h>
using namespace std;

void solve()
{
  int a[10];

  for(int i=0;i<10;i++)
    cin>>a[i];

  int player_a = 0;
  int player_b = 0;

  for(int i=0;i<10;i++)
  {
    if(a[i]==1)
    {
      if(i%2==0)
        player_a++;
      else
        player_b++;
    }
  }

  if(player_b==player_a)
    cout<<0<<endl;
  else if(player_a>player_b)
    cout<<1<<endl;
  else
    cout<<2<<endl;
}

int main()
{

  int t;
  cin>>t;

  while(t--)
    solve();
}

i want to know what is wrong with my solution plzz let me know
it show wrong answer while submitting

#include
using namespace std;

int main() {
int t,a[10],s1=0,s2=0;
cin>>t;
for(int i=0;i<t;i++)
{
for(int k=1;k<=10;k++)
{
cin>>a[k];
if(k%2==0)
s2+=a[k];
else
s1+=a[k];
}
if(s1>s2)
cout<<“1”<<endl;
else if(s2>s1)
cout<<“2”<<endl;
else
cout<<“0”<<endl;

}

return 0;

}