AtCoder Beginners Contest 087[A to C]

Tasks

 

A. Buying Sweets … Simple print modulus (=changes) result

x = int(input())
a = int(input())
b = int(input())

print((x-a)%b)

 

B. Coins … This takes N^3, and it’s much costly. And obviously there is a room for improvement.

a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1

print(count)

 

C. Candies … Iterate index one by one, so the cost is N.

n = int(input())
rows = []
for i in range(2):
    rows.append(list(map(int, input().split())))
 
max_candies = 0
for j in range(n):
    if sum(rows[0][:j+1]) + sum(rows[1][j:]) > max_candies:
        max_candies = sum(rows[0][:j+1]) + sum(rows[1][j:])
 
print(max_candies)

 

Leave a Reply

Your email address will not be published. Required fields are marked *