AtCoder Beginners Contest 088[A to C]



A. Infinite Coins … Simple print modulus result

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.

n = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)

if n > 1:


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.

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:
        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")