Commit 0c3ae2f 1 parent 58ed80b commit 0c3ae2f Copy full SHA for 0c3ae2f
File tree 4 files changed +62
-0
lines changed
4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+ from typing import List
3
+ import heapq
4
+
5
+
6
+ def solve ():
7
+ N : int = int (sys .stdin .readline ().strip ())
8
+ heap : List [int ] = []
9
+ heapq .heapify (heap )
10
+
11
+ for _ in range (N ):
12
+ n : int = int (sys .stdin .readline ().strip ())
13
+
14
+ if n == 0 :
15
+ if len (heap ) == 0 :
16
+ print (0 )
17
+ else :
18
+ print (heapq .heappop (heap ))
19
+ else :
20
+ heapq .heappush (heap , n )
21
+
22
+
23
+ if __name__ == '__main__' :
24
+ solve ()
Original file line number Diff line number Diff line change
1
+ 9
2
+ 0
3
+ 12345678
4
+ 1
5
+ 2
6
+ 0
7
+ 0
8
+ 0
9
+ 0
10
+ 32
Original file line number Diff line number Diff line change
1
+ 0
2
+ 1
3
+ 2
4
+ 12345678
5
+ 0
Original file line number Diff line number Diff line change
1
+ import sys
2
+ from pathlib import Path
3
+ from unittest import TestCase
4
+ from main import solve
5
+
6
+
7
+ class Test (TestCase ):
8
+ def my_solve (self , testcase_input ):
9
+ sys .stdin = open (testcase_input , 'r' )
10
+ stdout = sys .stdout
11
+ sys .stdout = open ('stdout.txt' , 'w' )
12
+ solve ()
13
+ sys .stdout .close ()
14
+ sys .stdout = stdout
15
+
16
+ def test_solve (self , testcase_number : str ):
17
+ self .my_solve ('test' + testcase_number + '.txt' )
18
+ self .assertEqual (
19
+ Path ('test' + testcase_number + '_answer.txt' ).read_text ().strip (),
20
+ Path ('stdout.txt' ).read_text ().strip ())
21
+
22
+ def test1_solve (self ):
23
+ self .test_solve ('1' )
You can’t perform that action at this time.
0 commit comments