Problem p03037 (python)

Fixed submission:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n, m = map(int, input().split())
a = [0] * (n + 2)
r = defaultdict(int)
for i in range(m):
    x,y = map(int,input().split())
    a[x - 1] += 1
    a[y] += -1

for i in range(n + 1):
    a[i + 1] += a[i]
count = 0
flg = True
for i in range(n):
    if a[i] >= m:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
a = readl()
a.sort()
d = defaultdict(int)
for i in a:
    if d[i]:
        d[i] += 1
    else:
        d[i] = 1

for i in range(m):
    x, y = map(int, input().split())
    for j in sorted(d):
        if y > j:
            w = d[j]
            ww = x
            d[j] -= ww
            x -= w
            d[y] += min(ww, w)
            if d[j] <= 0:
                del d[j]
            if x <= 0:
                break
        else:
            break
count = 0
for i in d:
    count += max(int(d[i]) * int(i),0)
print(count)

Buggy submission (verdict: Runtime Error):
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
a = deque([0])* (10 ** 5 + 10)
for i in range(m):
    x,y = map(int,input().split())
    a[x] = 1
    a[y + 1] = -1
for i in range(n + 3):
    a[i + 1] += a[i]
print(a.count(max(a)))

Buggy submission (verdict: Runtime Error):
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
a = deque([0] )* (10 ** 5 + 2)
q = [readl() for _ in range(m)]
for i in q:
    a[i[0]] = 1
    a[i[1] + 1] = -1
for i in range(n + 1):
    a[i + 1] += a[i]
print(a.count(max(a)))

Buggy submission (verdict: Runtime Error):
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
a = deque([0] )* (n + 2)
q = [readl() for _ in range(m)]
for i in q:
    a[i[0]] = 1
    a[i[1] + 1] = -1
for i in range(n + 1):
    a[i + 1] += a[i]
print(a.count(max(a)))

Buggy submission (verdict: Runtime Error):
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
a = deque([0] )* (n + 2)
for i in range(m):
    x,y = readmi()
    a[x] = 1
    a[y + 1] = -1
for i in range(n + 1):
    a[i + 1] += a[i]
print(a.count(max(a)))