답안 #348435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348435 2021-01-15T02:24:01 Z khoaipx Pod starim krovovima (COCI20_psk) Python 3
50 / 50
257 ms 3308 KB
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()
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2924 KB Output is correct
2 Correct 17 ms 2924 KB Output is correct
3 Correct 16 ms 2924 KB Output is correct
4 Correct 16 ms 2924 KB Output is correct
5 Correct 17 ms 2924 KB Output is correct
6 Correct 19 ms 3180 KB Output is correct
7 Correct 18 ms 3052 KB Output is correct
8 Correct 257 ms 3304 KB Output is correct
9 Correct 82 ms 3180 KB Output is correct
10 Correct 146 ms 3308 KB Output is correct