제출 #348435

#제출 시각아이디문제언어결과실행 시간메모리
348435khoaipxPod starim krovovima (COCI20_psk)Cpython 3
50 / 50
257 ms3308 KiB
import sys


def read_input(input_path=None):
    if input_path is None:
        f = sys.stdin
    else:
        f = open(input_path, 'r')

    n = int(f.readline().rstrip())
    cups = list()
    for _ in range(n):
        c, v = map(int, f.readline().split())
        cups.append((c, v))

    return n, cups


def sol(n, cups):
    i_cups = list()
    for i, cup in enumerate(cups):
        i_cups.append([i, cup[0], cup[1]])

    i_cups = sorted(i_cups, key=lambda x: x[2])

    for i in range(n - 1):
        c = i_cups[i][1]
        j = i + 1
        while c > 0 and j < n:
            t = i_cups[j][1]
            i_cups[j][1] = min(i_cups[j][2], i_cups[j][1] + c)
            c = c - (i_cups[j][1] - t)
            i_cups[i][1] = c
            j += 1
    i_cups = sorted(i_cups, key=lambda x: x[0])

    num_empty = 0
    for cup in i_cups:
        if cup[1] == 0:
            num_empty += 1

    lines = list()
    lines.append(f"{num_empty}")
    lines.append(f"{' '.join(map(str, [cup[1] for cup in i_cups]))}")

    return lines


def answer(input_path=None):
    return sol(*read_input(input_path))


def main():
    for line in sol(*read_input()):
        print(f"{line}")


if __name__ == '__main__':
    main()
#Verdict Execution timeMemoryGrader output
Fetching results...