BID - Editorial

PROBLEM LINK:

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

Author: kingmessi
Tester: watoac2001
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

You’re given the attack and defense values of each player of two teams.
If one team’s total attack and defense are both higher than the other team’s, you’ll bet on the stronger team; otherwise you’ll bet on a draw.
What result will you bet on?

EXPLANATION:

The total attack power of a team is the sum of their individual attack powers.
So, the total attack power of team A is

SA = attA_1 + attA_2 + \ldots + attA_N

Similarly, the total attack power of team P is

SP = attP_1 + attP_2 + \ldots + attP_N

In similar fashion, you can compute the total defense powers of both teams as the sum of their individual defense powers; and store these in variables DA and DP.

Then,

  • If SA\gt SP and DA\gt DP, bet on team A.
  • If SA\lt SP and DA\lt DP, bet on team P.
  • Otherwise, bet on a draw.

TIME COMPLEXITY:

\mathcal{O}(N) per testcase.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    n = int(input())
    aa = list(map(int, input().split()))
    da = list(map(int, input().split()))
    ap = list(map(int, input().split()))
    dp = list(map(int, input().split()))
    
    if sum(aa) > sum(ap) and sum(da) > sum(dp): print('A')
    elif sum(aa) < sum(ap) and sum(da) < sum(dp): print('P')
    else: print('Draw')