alexjercan/bugnet huggingface dataset:
Problem p02787 (Python) — buggy submission, verdict: Runtime Error

H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])

dp = [0] * (H + 1)
for h in range(1, H + 1):
    dp[h] = min([dp[max(h - a, 0)] + b for a, b in AB])

print(dp[-1])


Error: 0

Fixed submission:

H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])

dp = [0] * (H + 1)
for h in range(1, H + 1):
    dp[h] = min([dp[h - a] + b for a, b in AB])

print(dp[-1])
Problem p02787 (Python) — buggy submission, verdict: Time Limit Exceeded

(h, n), *m = [[*map(int, i.split())] for i in open(0)]
dp = [0] + [10**9] * h
for i in range(1, h + 1):
    for a, b in m:
        dp[i] = min(dp[i], dp[max(i - a, 0)] + b)
print(dp[-1])


Error: TLE

Fixed submission:

#!/usr/bin/env python3
(h, n), *m = [[*map(int, i.split())] for i in open(0)]
dp = [0] + [10**9] * h
for i in range(1, h + 1):
    dp[i] = min(dp[max(i - a, 0)] + b for a, b in m)
print(dp[-1])
Problem p02787 (Python) — buggy submission, verdict: Time Limit Exceeded

import numpy as np


def inpl():
    return list(map(int, input().split()))


H, N = inpl()
AB = [inpl() for i in range(N)]

A, B = np.array(AB, dtype=np.int64).reshape(N, 2).T

dp = np.zeros(H + 1, dtype=np.int64)
for i in range(1, H + 1):
    dp[i] = np.amin(dp[np.maximum(i - A, 0)] + B)

print(dp[H])


Error: TLE

Fixed submission:

def inpl():
    return list(map(int, input().split()))


H, N = inpl()
AB = [inpl() for i in range(N)]

# print(AB)
ans = [float("inf") for _ in range(H + 1)]
ans[0] = 0

for a, b in AB:
    # print(a, b)
    for i in range(H):
        ni = min(i + a, H)
        # print(i)
        ans[ni] = min(ans[ni], ans[i] + b)

print(ans[H])
Problem p02787 (Python) — buggy submission, verdict: Time Limit Exceeded

h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [0] * (h + max(a for a, b in ab))
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])


Error: TLE

Fixed submission:

MAX_LIMIT = 1e30
H, N = list(map(int, input().split()))
A, B = [], []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)  # HP
    B.append(b)  # power

# dp[i] means minimum power used to reduce HP i
dp = [MAX_LIMIT] * (H + max(A))
dp[0] = 0

for i in range(1, H + max(A)):
    cands = []
    for a, b in zip(A, B):
        if i - a >= 0:
            cands.append(b + dp[i - a])
    if len(cands) == 0:
        dp[i] = MAX_LIMIT  # we cannot directly reach this point
    else:
        dp[i] = min(cands)

# print(dp)
print(min(dp[H:]))
Problem p02787 (Python) — buggy submission, verdict: Runtime Error

from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

H, N = map(int, input().split())

AB = []
for i in range(N):
    A, B = map(int, input().split())
    AB.append((A, B))

AB.sort(key=lambda ab: (ab[0] / ab[1], -ab[0]), reverse=True)


@lru_cache(maxsize=None)
def solve(h):
    if h <= 0:
        return 0
    best = float("inf")
    for a, b in AB:
        val = b + solve(h - a)
        if val < best:
            best = val
        else:
            break
    return best


print(solve(H))


Error: TLE

Fixed submission:

# import itertools
# import math
import numpy as np


H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()

ans = 0
dp = np.zeros(H, dtype=int)
for a, b in AB:
    ans = max(ans, dp.max() + b)
    np.max(dp[:-a] + b, dp[a:], out=dp[a:])

print(ans)
Problem p02787 (Python) — buggy submission, verdict: Runtime Error

def main():
    h, n = map(int, input().split())
    magic_list = []

    for _ in range(n):
        a, b = map(int, input().split())
        magic_list.append((a, b))

    ans = solve(h, magic_list)
    print(ans)


def solve(h, magic_list):
    # 1-origin
    max_attack = max(magic_list)[0]
    dp = [0] * (h + max_attack)

    # time O(HN)
    for hp in range(1, h + 1):
        dp[hp] = min(dp[hp - attack] + mp for attack, mp in magic_list)

    return dp[h]


main()


Error: 0

Fixed submission:

def main():
    h, n = map(int, input().split())
    magic_list = []

    for _ in range(n):
        a, b = map(int, input().split())
        magic_list.append((a, b))

    ans = solve(h, magic_list)
    print(ans)


def solve(h, magic_list):
    # 1-origin
    dp = [0] * (h + 1)

    # time O(HN)
    for hp in range(1, h + 1):
        dp[hp] = min(dp[hp - attack] + mp for attack, mp in magic_list)

    return dp[h]


main()
Problem p02787 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

input = sys.stdin.readline
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for i in range(1, H + max_damage):
    dp[i] = min(dp[i - damage] + cost for damage, cost in magic)

ans = min(dp[H:])

print(ans)


Error: TLE

Fixed submission:

import sys

input = sys.stdin.readline
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

dp = [0] * (H + 1)

for i in range(1, H + 1):
    dp[i] = min(dp[max(i - damage, 0)] + cost for damage, cost in magic)

ans = dp[H]

print(ans)
Problem p02787 (Python) — buggy submission, verdict: Time Limit Exceeded

import numpy as np
from numba import njit, i8


@njit(i8(i8, i8, i8[:, :]), cache=True)
def solve(H, N, magics):
    dp = np.full((H + 1), 1 << 31, dtype=np.int64)
    dp[0] = 0
    for i in range(N):
        A, B = magics[i]
        for h in range(H):
            dp[min(h + A, H)] = min(dp[min(h + A, H)], dp[h] + B)
    return dp[-1]


H, N, *AB = map(int, open(0).read().split())
magics = np.array([(A, B) for A, B in zip(*[iter(AB)] * 2)], dtype=np.int64)
print(solve(H, N, magics))


Error: TLE

Fixed submission:

H, N, *AB = map(int, open(0).read().split())
magics = [(A, B) for A, B in zip(*[iter(AB)] * 2)]
dp = [float("inf")] * (H + 1)
dp[0] = 0
for i in range(N):
    A, B = magics[i]
    for h in range(H):
        dp[min(h + A, H)] = min(dp[min(h + A, H)], dp[h] + B)
print(dp[-1])
Problem p02787 (Python) — buggy submission, verdict: Time Limit Exceeded

h, n = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
a, b = x[0]
dp = [-(-i // a) * b for i in range(h + 1)]
for j in range(1, n):
    a, b = x[j]
    for i in range(min(h + 1, a)):
        dp[i] = min(dp[i], b)
    for i in range(a, h + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
print(dp[-1])


Error: TLE

Fixed submission:

h, n = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
a, b = x[0]
dp = [-(-i // a) * b for i in range(h + 1)]
for j in range(1, n):
    a, b = x[j]
    for i in range(h + 1):
        if i >= a:
            dp[i] = min(dp[i], dp[i - a] + b)
        else:
            dp[i] = min(dp[i], b)
print(dp[-1])
Problem p02787 (Python) — buggy submission, verdict: Runtime Error

h, n, *L = map(int, open(0).read().split())
dp = [0] * (h + 99999)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in zip(*[iter(L)] * 2))

print(dp[h])


Error: 0

Fixed submission:

h, n, *L = map(int, open(0).read().split())
dp = [0] * (h + 1)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in zip(*[iter(L)] * 2))

print(dp[h])
Problem p02787 (Python) — buggy submission, verdict: Runtime Error

import numpy as np

h, n = map(int, raw_input().split())
a = np.zeros(n, dtype=int)
b = np.zeros(n, dtype=int)
for i in range(n):
    a[i], b[i] = map(int, raw_input().split())
dp = np.zeros(10001, dtype=int)
for i in range(1, 10001):
    dp[i] = (dp[i - a] + b).min()
print(dp[h])


Error: TLE

Fixed submission:

import numpy as np


h, n = map(int, input().split())
a = np.zeros(n, dtype=int)
b = np.zeros(n, dtype=int)
for i in range(n):
    a[i], b[i] = map(int, input().split())
dp = np.zeros(10001, dtype=int)
for i in range(1, 10001):
    dp[i] = (dp[i - a] + b).min()
print(dp[h])
Problem p02787 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys
import functools


def inpl():
    return list(map(int, input().split()))


@functools.lru_cache(maxsize=None)
def solve(h):
    if h <= 0:
        return 0

    ret_val = float("inf")
    for a, b in AB:
        val = b + solve(h - a)
        if val < ret_val:
            ret_val = val
        else:
            break
    return ret_val


sys.setrecursionlimit(100000)

H, N = inpl()
AB = [inpl() for i in range(N)]
AB.sort(key=lambda ab: (ab[0] / ab[1], -ab[0]), reverse=True)
# print(AB)
print(solve(H))


Error: TLE

Fixed submission:

import sys
import functools


def inpl():
    return list(map(int, input().split()))


@functools.lru_cache(maxsize=None)
def solve(h):
    if h <= 0:
        return 0

    ret_val = float("inf")
    for a, b in AB:
        ret_val = min(ret_val, b + solve(h - a))
    return ret_val


sys.setrecursionlimit(100000)

H, N = inpl()
AB = [inpl() for i in range(N)]
AB.sort(key=lambda ab: (ab[0] / ab[1], -ab[0]), reverse=True)
# print(AB)
print(solve(H))
Problem p02788 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
q = deque()
t = 0
result = 0
for x, h in XH:
    while q:
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.popleft()
    h -= t
    if h <= 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)


Error: TLE

Fixed submission:

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while q:
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h <= 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)
Problem p02788 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque


def main():
    N, D, A = map(int, input().split())

    XHN = []
    for _ in range(N):
        X, H = map(int, input().split())
        XHN.append([X, H, X + 2 * D])

    XHN.sort()

    q = deque()
    acc_damege = 0
    ans = 0
    for i in range(N):
        if 0 < XHN[i][1]:
            X, H, bomb_p = XHN[i]

            while q:
                acc_x, acc_d = q[0]
                if acc_x < X:
                    acc_damege -= acc_d
                    del q[0]
                else:
                    break

            H -= acc_damege

            if 0 < H:
                attack_count = H // -A * -1
                damege = A * attack_count
                ans += attack_count
                XHN[i][1] -= damege

                acc_damege += damege
                q.append((bomb_p, damege))

    print(ans)


main()


Error: TLE

Fixed submission:

def main():
    N, D, A = map(int, input().split())

    XHN = []
    for _ in range(N):
        X, H = map(int, input().split())
        XHN.append([X, H, X + 2 * D])

    XHN.sort()

    q = []
    acc_damege = 0
    ans = 0
    for i in range(N):
        if 0 < XHN[i][1]:
            X, H, bomb_p = XHN[i]

            while q:
                acc_x, acc_d = q[0]
                if acc_x < X:
                    acc_damege -= acc_d
                    del q[0]
                else:
                    break

            H -= acc_damege

            if 0 < H:
                attack_count = H // -A * -1
                damege = A * attack_count
                ans += attack_count
                XHN[i][1] -= damege

                acc_damege += damege
                q.append((bomb_p, damege))

    print(ans)


main()
Problem p02788 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque

n, d, a = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(n)]
m.sort()
r = 1
d *= 2
q = deque([])
for i in range(n):
    while r < n and m[i][0] + d >= m[r][0]:
        r += 1
    m[i].append(r)
    m[i][1] = (m[i][1] + a - 1) // a
res = 0
tdamage = 0
for i in range(n):
    while q and q[0][0] <= i:
        minus = q.popleft()
        tdamage -= minus[1]
    m[i][1] -= tdamage
    if m[i][1] > 0:
        res += m[i][1]
        tdamage += m[i][1]
        q.append([m[i][2], m[i][1]])
print(res)


Error: TLE

Fixed submission:

n, d, a = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(n)]
m.sort()
if m[0][1] < m[-1][1]:
    for i in range(n):
        m[i][0] = m[i][0] * (-1)
    m.reverse()
bomb = [0 for _ in range(n)]
r = 1
d *= 2
for i in range(n):
    while r < n and m[i][0] + d >= m[r][0]:
        r += 1
    bomb[i] = r - 1
res = 0
for i in range(n):
    if m[i][1] > 0:
        tres = (m[i][1] + a - 1) // a
        res += tres
        dh = tres * a
        for j in range(i, bomb[i] + 1):
            m[j][1] -= dh
print(res)
Problem p02788 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque
import sys


N, D, A = map(int, input().split())
M = [tuple(map(int, x.split())) for x in sys.stdin.readlines()]
M.sort()

q = deque()
qt = deque()

ans = 0
dmg = 0
for x, h in M:
    if len(q) == 0:
        bomb = (h + A - 1) // A
        q.append((x + 2 * D, bomb))
        dmg += bomb * A
        ans += bomb
    else:
        while len(q) > 0:
            d, bomb = q.popleft()
            if d < x:
                dmg -= bomb * A
            else:
                q.appendleft((d, bomb))
                break
        if h > dmg:
            bomb = ((h - dmg) + A - 1) // A
            q.append((x + 2 * D, bomb))
            dmg += bomb * A
            ans += bomb

print(ans)


Error: TLE

Fixed submission:

from collections import deque
import sys


N, D, A = map(int, input().split())
M = [tuple(map(int, x.split())) for x in sys.stdin.readlines()]
M.sort()

q = deque()
qt = deque()

ans = 0
for x, h in M:
    if len(q) == 0:
        bomb = (h + A - 1) // A
        q.append((x + 2 * D, bomb))
        ans += bomb
    else:
        while h > 0:
            d, bomb = q.popleft()
            if x <= d:
                h -= bomb * A
                qt.append((d, bomb))
            if h > 0 and len(q) == 0:
                bomb = (h + A - 1) // A
                h -= bomb * A
                qt.append((x + 2 * D, bomb))
                ans += bomb
        while len(qt) > 0:
            q.appendleft(qt.pop())

print(ans)
Problem p02788 (Python) — buggy submission, verdict: Time Limit Exceeded

N, D, A = map(int, input().split())
XH = [tuple(map(int, input().split())) for _ in range(N)]
XH.sort()


ans = 0
bomb_effect = 0
bomb_i = 0
bombs = []
for x, h in XH:
    while (bomb_i < len(bombs)) and (x > bombs[bomb_i][0]):
        bomb_effect -= bombs[bomb_i][1] * A
        bomb_i += 1

    tairyoku = h - bomb_effect
    if tairyoku > 0:
        new_bomb = -((-tairyoku) // A)
        ans += new_bomb
        bombs.append((x + 2 * D + 0.5, new_bomb))
        bomb_effect += new_bomb * A

print(ans)


Error: TLE

Fixed submission:

from heapq import heapify, heappush, heappop

N, D, A = map(int, input().split())
XH = [tuple(map(int, input().split())) for _ in range(N)]

heap = [(x, h, True) for x, h in XH]
heapify(heap)

ans = 0
bomb_effect = 0
while heap:
    x, h, monster_flg = heappop(heap)
    if monster_flg:
        tairyoku = h - bomb_effect
        if tairyoku > 0:
            new_bomb = -((-tairyoku) // A)
            ans += new_bomb
            heappush(heap, (x + 2 * D + 0.5, new_bomb, False))
            bomb_effect += new_bomb * A
    else:
        bomb_effect -= h * A

print(ans)
Problem p02788 (Python) — buggy submission, verdict: Time Limit Exceeded

from heapq import heapify, heappush, heappop
from math import ceil

REAL = 0
UNREAL = 1

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

hp = []
for x, h in xh:
    heappush(hp, [x, REAL, h])

bomb_acm = 0
ans = 0
while hp:
    x, r, h = heappop(hp)
    if r == REAL:
        if h > bomb_acm:
            left = h - bomb_acm
            bomb_cnt = ceil(left / a)
            hp_dis = a * bomb_cnt
            bomb_acm += hp_dis
            heappush(hp, [x + 2 * d, UNREAL, hp_dis])
            ans += bomb_cnt

    else:  # r == UNREAL
        bomb_acm -= h

print(ans)


Error: TLE

Fixed submission:

from heapq import heapify, heappop, heappush
from math import ceil
import sys

input = sys.stdin.readline


def main():
    n, d, a = map(int, input().split())
    hp = [list(map(int, input().split())) for _ in range(n)]
    heapify(hp)

    ans = 0

    while hp:
        left = heappop(hp)
        cnt = ceil(left[1] / a)
        li = []
        while hp and hp[0][0] <= left[0] + 2 * d:
            nxt = heappop(hp)
            if nxt[1] - a * cnt > 0:
                li.append([nxt[0], nxt[1] - a * cnt])

        for e in li:
            heappush(hp, e)

        ans += cnt

    print(ans)


if __name__ == "__main__":
    main()
Problem p02788 (Python) — buggy submission, verdict: Time Limit Exceeded

from sys import stdin
from collections import deque

n, d, a = (int(v) for v in stdin.readline().split())
monsters = [(int(v) for v in line.split()) for line in stdin.readlines()]

monsters = [[x, (h // a + 1) if h % a > 0 else (h // a)] for x, h in monsters]
monsters = sorted(monsters)
bomb_size = 2 * d + 1
num_bombs = 0

current_bombs = 0
bomb_endpoints = deque()
bomb_endnumbers = deque()

for i in range(len(monsters)):
    while len(bomb_endpoints) > 0 and bomb_endpoints[0] <= monsters[i][0]:
        current_bombs -= bomb_endnumbers[0]
        bomb_endpoints.popleft()
        bomb_endnumbers.popleft()
    monsters[i][1] -= current_bombs
    if monsters[i][1] > 0:
        bombs_now = monsters[i][1]
        monsters[i][1] = 0
        num_bombs += bombs_now
        current_bombs += bombs_now
        bomb_endpoints.append(monsters[i][0] + bomb_size)
        bomb_endnumbers.append(bombs_now)

print(num_bombs)


Error: TLE

Fixed submission:

from sys import stdin

n, d, a = (int(v) for v in stdin.readline().split())
monsters = [(int(v) for v in stdin.readline().split()) for i in range(n)]

monsters = [[x, (h // a + 1) if h % a > 0 else (h // a)] for x, h in monsters]
monsters = sorted(monsters)
bomb_size = 2 * d + 1
num_bombs = 0

ptr = 0
while ptr < len(monsters):
    while ptr < len(monsters) and monsters[ptr][1] <= 0:
        ptr += 1
    if ptr < len(monsters):
        position = monsters[ptr][0]
        bombs_now = monsters[ptr][1]
        i = ptr
        while i < len(monsters) and monsters[i][0] - position < bomb_size:
            monsters[i][1] -= bombs_now
            i += 1
        num_bombs += bombs_now

print(num_bombs)
Problem p02789 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())

if n == m:
    print("Yes")
else:
    print("No")


Error: 0

Fixed submission:

n, m = map(int, input().split())

if n / m == 1:
    print("Yes")
else:
    print("No")
Problem p02790 (Python) — buggy submission, verdict: Runtime Error

data = input().split()

a = data[0]
b = data[1]

ans = min(a, b) * int(max(a, b))

print(ans)


Error: TypeError: can't multiply sequence by non-int of type 'str'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02790/Python/s088084103.py", line 6, in <module>
    ans = min(a, b) * max(a, b)
TypeError: can't multiply sequence by non-int of type 'str'


Fixed submission:

data = input().split()

a = data[0]
b = data[1]

ans = min(a, b) * max(a, b)

print(ans)
Problem p02791 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
P = list(map(int, input().split()))

"""
参考
https://cocoinit23.com/abc152/
すべての(i, j)を調べていると制限時間を超過してしまう。
listの2つ目の要素(index=1)から順に見ていって、最小値が更新されたら解をカウントアップする。
ただし、解の最小値は常に1となるので、解の初期値は1にしておくこと。
"""
ans = 1
min_p = P[0]

for i in range(1, N):
    if P[i] <= min_p:
        min_p = P[i]
        ans += 1

print(ans)


Error: TLE

Fixed submission:

N = int(input())
P = list(map(int, input().split()))
ans = 1

for i in range(1, N):
    if P[i] <= min(P[:i]):
        ans += 1

print(ans)
Problem p02791 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
p = list(map(int, input().split()))
t = n
c = 0
for i in range(n):
    t = min(t, p[i])
    if p[i] <= t:
        c += 1
print(c)


Error: TLE

Fixed submission:

n = int(input())
p = list(map(int, input().split()))
t = []
c = 0
for i in p:
    t += [i]
    if i <= min(t):
        c += 1
print(c)
Problem p02791 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
p_list = list(map(int, input().split()))
ans = 1
min = p_list[0]
for i in range(1, n):
    if min >= p_list[i]:
        ans += 1
        min = p_list[i]
print(ans)


Error: TLE

Fixed submission:

n = int(input())
p_list = list(map(int, input().split()))
ans = 1
for i in range(1, n):
    if all([p_list[i] <= p_list[j] for j in range(i)]):
        ans += 1
print(ans)
Problem p02791 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
p = list(map(int, input().split()))

q = p[0]
p = p[1:]

m = 1

if n > 1:
    for pi in p:
        if q > pi:
            m += 1
            q = pi

print(m)


Error: TypeError: 'map' object is not subscriptable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02791/Python/s560223723.py", line 9, in <module>
    elif all([pj >= pi for pj in p[:i]]):
TypeError: 'map' object is not subscriptable


Fixed submission:

n = int(input())
p = map(int, input().split())
m = 1

if n > 1:
    for i, pi in enumerate(p):
        if pi <= i:
            continue
        elif all([pj >= pi for pj in p[:i]]):
            m += 1
        else:
            continue

print(m)
Problem p02791 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
P = list(map(int, input().split()))

value = 10**9
ans = 0
for v in P:
    if v < value:
        ans += 1
        value = v
print(ans)


Error: TLE

Fixed submission:

import numpy as np

N = int(input())
P = list(map(int, input().split()))

value = np.array(P)

ac = [v for i, v in enumerate(P) if v == np.minimum.accumulate(P)[i]]

print(len(ac))
Problem p02791 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
p = list(map(int, input().split()))

max0, max1, count = p[0], 0, 0
for i in p:
    max0 = min(max0, i)
    max1 = i
    if max1 == 1:
        count += 1
        break
    elif max0 >= max1:
        count += 1
print(count)


Error: TLE

Fixed submission:

N = int(input())
p = list(map(int, input().split()))

max0, max1, count = [], 0, 0
for i in p:
    max0.append(i)
    max1 = i
    if max1 == 1:
        count += 1
        break
    elif min(max0) >= max1:
        count += 1
print(count)
Problem p02791 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
P = map(int, input().split())

m = next(P)
c = 1
for p in P:
    if p <= m:
        m = p
        c += 1
print(c)


Error: TLE

Fixed submission:

N = int(input())
P = list(map(int, input().split()))

c = 0
try:
    while P:
        p_i = P.pop()
        if p_i <= min(P):
            c += 1
except ValueError:
    print(c + 1)
Problem p02791 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
p = list(map(int, input().split()))
# result_list = [0]*n
result = 1
com_val = p[0]

for i in range(1, n):
    if com_val < p[i]:
        continue
    else:
        result += 1
        com_val = p[i]

print(result)


Error: TLE

Fixed submission:

n = int(input())
p = list(map(int, input().split()))
# result_list = [0]*n
result_count = 0

for i in range(n):
    for j in range(i):
        if p[i] > p[j]:
            # result_list[i] = 1
            result_count += 1
            break

# print(result_list.count(0))
print(n - result_count)
Problem p02791 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
P = list(map(int, input().split()))
Q = []
m = 10**17
for p in P:
    m = min(m, p)
    Q.append(m)
c = 0
for x, y in zip(P, Q):
    if x <= y:
        c += 1
print(c)


Error: TLE

Fixed submission:

N = int(input())
P = list(map(int, input().split()))
print(1 + sum([int(P[i] <= min(P[:i])) for i in range(1, N)]))