# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
348435 | khoaipx | Pod starim krovovima (COCI20_psk) | Cpython 3 | 257 ms | 3308 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |