Submission #1336476

#TimeUsernameProblemLanguageResultExecution timeMemory
1336476nguyengiabach1201Coins (BOI06_coins)Pypy 3
0 / 100
150 ms48764 KiB
def solve():
    # Read N and K
    N, K = map(int, input().split())
    coins = []
    for _ in range(N):
        coins.append(list(map(int, input().split())))

    current_sum = 0
    new_coin_count = 0

    for i in range(N):
        val, already_owned = coins[i]
        
        # Determine the upper bound for the current sum
        limit = coins[i+1][0] if i + 1 < N else K
        
        if already_owned == 0:
            # If we don't have this coin, try to add it
            if current_sum + val < limit:
                current_sum += val
                new_coin_count += 1
        else:
            # If we already have it, we skip it to keep the sum minimal.
            # However, we must ensure our existing sum is still valid 
            # for the current limit (which it will be, since current_sum < val < limit)
            pass

    # Special case: if no new coins can be acquired, the best price is K-1
    if new_coin_count == 0:
        print(0)
        print(K - 1)
    else:
        print(new_coin_count)
        print(K - current_sum)

Compilation message (stdout)

Compiling 'coins.py'...

=======
  adding: __main__.pyc (deflated 30%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...