A. Infinite Coins … Simple print modulus result

1 2 3 4 |
n = int(input()) a = int(input()) print("Yes" if n%500 <= a else "No") |

B. Card Game For Two … As the questions says “When both players take the optimal strategy to maximize their scores”, it means both player takes the biggest card on their turn. Sort the card list in descending order, and use python list slice ([::2] the last 2 means every other cards) to create the resulting card list for both users.

1 2 3 4 5 6 7 |
n = int(input()) cards = sorted(list(map(int, input().split())), reverse=True) if n > 1: print(sum(cards[::2])-sum(cards[1::2])) else: print(cards[0]) |

C. Takahashi’s Information … As possible number of ai is not so big, I use bruteforce for possible a1, so the cost is 100x3x3. Once a1 value is fixed, the other number can be calculated. Compare the resulting list (from the assumption) and the original list.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
def is_correct(grids): for a1 in range(min(101, grids[0][0]+1)): b_list = grids[0][0] - a1, grids[0][1] - a1, grids[0][2] - a1 a2, a3 = grids[1][0] - b_list[0], grids[2][0] - b_list[0] a_list = [a1, a2, a3] temp_grids = [] for an in a_list: row = [] for bn in b_list: row.append(an+bn) temp_grids.append(row) if grids == temp_grids: return True return False grids = [] for _ in range(3): grids.append(list(map(int, input().split()))) print("Yes" if is_correct(grids) else "No") |