Problem p02948 (python)

Fixed submission:

import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    N, M = LMIIS()
    dp = [0] * (M+1)

    DV = [[0] for _ in range(M+1)]

    for _ in range(N):
        A,B = LMIIS()
        if A > M:
            continue
        DV[A].append(B)


    from heapq import heappush, heappop
    ans = 0
    h = []
    for l in DV:
        for item in l:
            heappush(h,-item)
        ans -= heappop(h)
    print(ans)
        
        



    pass
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
wanidonMacbook:~ yc$ cd Dropbox/code/atcoder/abc
wanidonMacbook:abc yc$ ls
124     126     127     128     132     133     134     135     136     a.py    b.py    c.py    d.py
wanidonMacbook:abc yc$ mkdir 137
wanidonMacbook:abc yc$ cd ../
wanidonMacbook:atcoder yc$ ls
__pycache__     agc             hoge            modint.py       testModInt.py
abc             gcd.py          hoge.py         templete.py
wanidonMacbook:atcoder yc$ cp templete.py abc/137/a.py
wanidonMacbook:atcoder yc$ cd abc/137/a.py 
bash: cd: abc/137/a.py: Not a directory
wanidonMacbook:atcoder yc$ cd abc/137/
wanidonMacbook:137 yc$ ls
a.py
wanidonMacbook:137 yc$ cp a.py b.py
wanidonMacbook:137 yc$ cp a.py v.py
wanidonMacbook:137 yc$ cp a.py c.py
wanidonMacbook:137 yc$ cp a.py d.py
wanidonMacbook:137 yc$ code c.py 
wanidonMacbook:137 yc$ python3 d.py 
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraintTraceback (most recent call last):
  File "c.py", line 32, in <module>
    main()
  File "c.py", line 13, in main
    d = defaultdict(0)
TypeError: first argument must be callable or None
wanidonMacbook:137 yc$ acornistnt
bash: acornistnt: command not found
wanidonMacbook:137 yc$ peanutbomb
bash: peanutbomb: command not found
wanidonMacbook:137 yc$ constraint
bash: constraint: command not found
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
defaultdict(<function main.<locals>.<lambda> at 0x100b01d90>, {1563547937388403509070898085: 2, 20694617904755669861703772485: 1})
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraintacornistnt
peanutbomb

constraint
defaultdict(<function main.<locals>.<lambda> at 0x10c7fdd90>, {1563547937388403509070898085: 2, 20694617904755669861703772485: 1})
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraintacornistnt
peanutbomb

constraint
defaultdict(<function main.<locals>.<lambda> at 0x102e1cd90>, {1563547937388403509070898085: 2, 20694617904755669861703772485: 1})
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraintacornistnt
peanutbomb

constraint
defaultdict(<function main.<locals>.<lambda> at 0x10392ad90>, {1563547937388403509070898085: 2, 20694617904755669861703772485: 1})
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraintaaa= acornistnt
aaa= peanutbomb

aaa= constraint
defaultdict(<function main.<locals>.<lambda> at 0x100bebd90>, {1563547937388403509070898085: 2, 20694617904755669861703772485: 1})
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
aaa= acornistnt 


aaa= peanutbomb 



aaa= constraint 

defaultdict(<function main.<locals>.<lambda> at 0x10bd4fd90>, {1563547937388403509070898085: 2, 20694617904755669861703772485: 1})
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constrainta
c
o
r
n
i
s
t
n
t
p
e
a
n
u
t
b
o
m
b

c
o
n
s
t
r
a
i
n
t
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint0
2
14
17
13
8
18
19
13
19
15
4
0
13
20
19
1
14
12
1

2
14
13
18
19
17
0
8
13
19
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint0 1
2 676
14 64509974703297150976
17 1133827315385150725554176
13 2481152873203736576
8 208827064576
18 29479510200013918864408576
19 766467265200361890474622976
13 2481152873203736576
19 766467265200361890474622976
15 1677259342285725925376
4 456976
0 1
13 2481152873203736576
20 19928148895209409152340197376
19 766467265200361890474622976
1 26
14 64509974703297150976
12 95428956661682176
1 26

2 676
14 64509974703297150976
13 2481152873203736576
18 29479510200013918864408576
19 766467265200361890474622976
17 1133827315385150725554176
0 1
8 208827064576
13 2481152873203736576
19 766467265200361890474622976
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
0
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
dict_items([])
0
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
dict_items([(1563547937388403509070898085, 2), (20694617904755669861703772485, 1)])
Traceback (most recent call last):
  File "c.py", line 38, in <module>
    main()
  File "c.py", line 24, in main
    if n >= 2:
TypeError: '>=' not supported between instances of 'tuple' and 'int'
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
dict_values([2, 1])
Traceback (most recent call last):
  File "c.py", line 38, in <module>
    main()
  File "c.py", line 25, in main
    asn += n-1
UnboundLocalError: local variable 'asn' referenced before assignment
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
dict_values([2, 1])
1
wanidonMacbook:137 yc$ python3 c.py 
2
oneplustwo
ninemodsix
dict_values([1, 1])
0
wanidonMacbook:137 yc$ python3 c.py 
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
dict_values([3, 2])
3
wanidonMacbook:137 yc$ code ../../modint.py 
wanidonMacbook:137 yc$ code ../../modint.py 
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaawanidonMacbook:137 yc$ 5
bash: 5: command not found
wanidonMacbook:137 yc$ abaaaaaaaa
bash: abaaaaaaaa: command not found
wanidonMacbook:137 yc$ oneplustwo
bash: oneplustwo: command not found
wanidonMacbook:137 yc$ aaaaaaaaba
bash: aaaaaaaaba: command not found
wanidonMacbook:137 yc$ twoplusone
bash: twoplusone: command not found
wanidonMacbook:137 yc$ aaaabaaaaa
bash: aaaabaaaaa: command not found
wanidonMacbook:137 yc$ python3 c.py 
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
dict_values([3, 2])
4
wanidonMacbook:137 yc$ python3 c.py 
2
oneplustwo
ninemodsix
dict_values([1, 1])
0
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
dict_values([2, 1])
1
wanidonMacbook:137 yc$ python3 c.py 
3
acornistnt
peanutbomb
constraint
1
wanidonMacbook:137 yc$ code b.py 
wanidonMacbook:137 yc$ python3 b.py 
3 7
5
6
7
8
9
wanidonMacbook:137 yc$ python3 b.py 
4 0
-3
-2
-1
0
1
2
3
wanidonMacbook:137 yc$ python3 b.py 
1 100
100
wanidonMacbook:137 yc$ code a.py 
wanidonMacbook:137 yc$ python3 a.py 
-13 3
-10
wanidonMacbook:137 yc$ python3 a.py 
13 3
39
wanidonMacbook:137 yc$ code d.py 
wanidonMacbook:137 yc$ python3 a.py 
3 4
4 3
4 1
2 212
wanidonMacbook:137 yc$ 4 3
bash: 4: command not found
wanidonMacbook:137 yc$ 4 1
bash: 4: command not found
wanidonMacbook:137 yc$ python3 a.py 
^CTraceback (most recent call last):
  File "a.py", line 20, in <module>
    main()
  File "a.py", line 11, in main
    A,B = LMIIS()
  File "a.py", line 5, in <lambda>
    LMIIS = lambda : list(map(int,input().split()))
KeyboardInterrupt
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0, 0, 2, 0, 3]
wanidonMacbook:137 yc$ python3 d.py 
  File "d.py", line 19
    DV[A].append(B)
                  ^
IndentationError: unindent does not match any outer indentation level
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[[], [], [2], [], [1, 3]]
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
Traceback (most recent call last):
  File "d.py", line 36, in <module>
    main()
  File "d.py", line 27, in main
    ans += l.pop(0)
IndexError: pop from empty list
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2[[0], [0], [0], [0], [0]]

0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2[[0], [0], [0], [0], [0]]

[[0], [0], [0, 2], [0], [0, 3, 1]]
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2[[0], [0], [0], [0], [0]]

[[0], [0], [0, 2], [0], [0, 1, 3]]
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2[[0], [0], [0], [0], [0]]

[[0], [0], [0, 2], [0], [0, 1, 3]]
5
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3[[0], [0], [0], [0]]

[[0], [0, 2, 3, 4], [0, 1, 3], [0]]
7
wanidonMacbook:137 yc$ python3 d.py 
1 1
2 1[[0], [0]]

[[0], [0]]
0
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3[[0], [0], [0], [0]]

[[0], [0, 2, 3, 4], [0, 1, 3], [0]]
7
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3[[0], [0], [0], [0]]

[[0], [0, 2, 3, 4], [0, 1, 3], [0]]
[0]
[0, 0, 2, 3, 4]
[0, 0, 2, 3, 4, 0, 1, 3]
[0, 0, 2, 3, 4, 0, 1, 3, 0]
7
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3[[0], [0], [0], [0]]

[[0], [0, 2, 3, 4], [0, 1, 3], [0]]
[0]
[0, 0, 2, 3, 4]
[0, 0, 2, 3, 4, 0, 1, 3]
[0, 0, 2, 3, 4, 0, 1, 3, 0]
7
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3

[[0], [0], [0], [0]]
[[0], [0, 2, 3, 4], [0, 1, 3], [0]]
[0]
[0, 0, 2, 3, 4]
[0, 0, 0, 1, 2, 3, 3, 4]
[0, 0, 0, 0, 1, 2, 3, 3, 4]
7
wanidonMacbook:137 yc$ 
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3[[0], [0], [0], [0]]

[[0], [0, 2, 3, 4], [0, 1, 3], [0]]
[0]
[0, 2, 3, 4]
[0, 0, 1, 2, 3, 3]
[0, 0, 0, 1, 2, 3]
10
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3
10
wanidonMacbook:137 yc$ python3 d.py 
1 1
2 1
0
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3
10
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
5
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
Traceback (most recent call last):
  File "d.py", line 49, in <module>
    main()
  File "d.py", line 31, in main
    if maxv > DV[j][-1]:
IndexError: list index out of range
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0]
[]
Traceback (most recent call last):
  File "d.py", line 50, in <module>
    main()
  File "d.py", line 32, in main
    if maxv > DV[j][-1]:
IndexError: list index out of range
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0]
[]
Traceback (most recent call last):
  File "d.py", line 50, in <module>
    main()
  File "d.py", line 32, in main
    if len(DV)>=1 and maxv > DV[j][-1]:
IndexError: list index out of range
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0]
[]
[0]
Traceback (most recent call last):
  File "d.py", line 50, in <module>
    main()
  File "d.py", line 36, in main
    DV[maxi].pop()
IndexError: pop from empty list
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0]
[0]
[0]
[0]
[0]
[0, 2]
[0]
[0]
[0, 2]
[0]
-4
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0]
[0]
[0]
[0]
[0]
[0, 2]
[0]
[0]
[0, 2]
[0]
-4
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0]
[0]
[0]
[0]
[0]
[0, 2]
[0]
[0]
[0, 2]
[0]
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0]
[0]
[0, 2]
[0]
[0, 2]
[0]
[0]
[0, 2]
[0]
[0, 1, 3]
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
[0]
[0]
[0, 2]
[0]
[0, 2]
[0]
[0]
[0, 2]
[0]
[0, 1, 3]
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
0
0
2
0
2
0
0
2
0
3
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
0
0
2
0
2
0
0
2
0
3
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
0
0
2
a
0
0
0
0
0
0
3
a
5
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3
10
wanidonMacbook:137 yc$ python3 d.py 
1 1
2 1
0
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
Traceback (most recent call last):
  File "d.py", line 38, in <module>
    main()
  File "d.py", line 27, in main
    tmpL += D[i][:M-i+1]
NameError: name 'D' is not defined
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
2
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
3
wanidonMacbook:137 yc$ python3 d.py 
3 4
4 3
4 1
2 2
5
wanidonMacbook:137 yc$ python3 d.py 
5 3
1 2
1 3
1 4
2 1
2 3
10
wanidonMacbook:137 yc$ python3 d.py 
1 1
2 1
0
wanidonMacbook:137 yc$