Problem:


Score : 500 points

Problem Statement

Takahashi is at an all-you-can-eat restaurant.

The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.

The restaurant has the following rules:

You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.

You cannot order the same kind of dish more than once.

Until you finish eating the dish already served, you cannot order a new dish.

After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.

Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.

What is the maximum possible happiness achieved by making optimal choices?

Constraints

2 \leq N \leq 3000

1 \leq T \leq 3000

1 \leq A_i \leq 3000

1 \leq B_i \leq 3000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N T
A_1 B_1
:
A_N B_N

Output

Print the maximum possible happiness Takahashi can achieve.

Sample Input 1

2 60
10 10
100 100

Sample Output 1

110

By ordering the first and second dishes in this order, Takahashi's happiness will be 110.

Note that, if we manage to order a dish in time, we can spend any amount of time to eat it.

Sample Input 2

3 60
10 10
10 20
10 30

Sample Output 2

60

Takahashi can eat all the dishes within 60 minutes.

Sample Input 3

3 60
30 10
30 20
30 30

Sample Output 3

50

By ordering the second and third dishes in this order, Takahashi's happiness will be 50.

We cannot order three dishes, in whatever order we place them.

Sample Input 4

10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25

Sample Output 4

145



Sample input:
2 60
10 10
100 100


Sample output:
110

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0

    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    #if test:
    #    print(f"{n}C{r} = {ret}")
    return ret

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


#########################入力受付部
N, T = iip()
AB = []
A = []
B = []
for i in range(N):
    a, b = iip()
    AB.append((a, b))
    AB = sorted(AB, key=lambda x:x[1])

#########################入力受付部

def main():
    manzoku_list = [0 for i in range(T)]
    tabeta_list = [[] for i in range(T)]

    for i, ab in enumerate(AB):
        a = ab[0]
        b = ab[1]
        #print(a, b)
        manzoku_list2 = [i for i in manzoku_list]
        tabeta_list2 = [i for i in tabeta_list]
        for j, manzoku in enumerate(manzoku_list2):
            if not j+a >= T:
                if manzoku_list2[j+a] < manzoku+b:
                    manzoku_list[j+a] = manzoku+b
                    tt = tabeta_list2[j]
                    tt.append(i)
                    tabeta_list[j+a] = tt
        #print(tabeta_list)

    maxx = 0
    for i, ab in enumerate(AB):
        if not i in tabeta_list[T-1]:
            maxx = max(ab[1], maxx)


    ans = manzoku_list[T-1] + maxx

    #print(tabeta_list)
    #print(manzoku_list)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0

    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    #if test:
    #    print(f"{n}C{r} = {ret}")
    return ret

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


#########################入力受付部
N, T = iip()
A = []
B = []
for i in range(N):
    a, b = iip()
    A.append(a)
    B.append(b)


#########################入力受付部

def main():
    manzoku_list = [0 for i in range(T)]
    tabenokosi_list = [0 for i in range(T)]

    for a, b in zip(A, B):
        #print(a, b)
        manzoku_list2 = [i for i in manzoku_list]
        for i, manzoku in enumerate(manzoku_list2):
            if not i+a >= T:
                if manzoku_list2[i+a] < manzoku+b:
                    manzoku_list[i+a] = manzoku+b
                else:
                    tabenokosi_list[i] = max(tabenokosi_list[i], b)
            else:
                #print(manzoku)
                tabenokosi_list[i] = max(tabenokosi_list[i], b)

    #print(tabenokosi_list)
    #print(manzoku_list)
    ans = manzoku_list[T-1] + tabenokosi_list[T-1]
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0

    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    #if test:
    #    print(f"{n}C{r} = {ret}")
    return ret

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


#########################入力受付部
N, T = iip()
A = []
B = []
for i in range(N):
    a, b = iip()
    A.append(a)
    B.append(b)
Bmax = max(B)
im = B.index(Bmax)
A.pop(im)
B.pop(im)

#########################入力受付部

def main():
    manzoku_list = [0 for i in range(T)]

    for a, b in zip(A, B):
        #print(a, b)
        manzoku_list2 = [i for i in manzoku_list]
        for i, manzoku in enumerate(manzoku_list2):
            if i+a >= T:
                break
            manzoku_list[i+a] = max(manzoku_list2[i+a], manzoku+b)

    #print(manzoku_list)
    ans = manzoku_list[T-1] + Bmax
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0

    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    #if test:
    #    print(f"{n}C{r} = {ret}")
    return ret

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


#########################入力受付部
N, T = iip()
A = []
B = []
for i in range(N):
    a, b = iip()
    A.append(a)
    B.append(b)
Bmax = max(B)
im = B.index(Bmax)
A.pop(im)
B.pop(im)

#########################入力受付部

def main():
    manzoku_list = [0 for i in range(T)]

    for a, b in zip(A, B):
        #print(a, b)
        manzoku_list2 = [i for i in manzoku_list]
        for i, manzoku in enumerate(manzoku_list2):
            if i+a >= T:
                break
            manzoku_list[i+a] = max(manzoku_list2[i+a], manzoku+b)

    print(manzoku_list)
    ans = manzoku_list[T-1] + Bmax
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0

    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    #if test:
    #    print(f"{n}C{r} = {ret}")
    return ret

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


#########################入力受付部
N, T = iip()
A = []
B = []
for i in range(N):
    a, b = iip()
    A.append(a)
    B.append(b)
Bmax = max(B)
im = B.index(Bmax)
A.pop(im)
B.pop(im)

#########################入力受付部

def main():
    manzoku_list = [0 for i in range(T)]

    for a, b in zip(A, B):
        #print(a, b)
        manzoku_list2 = [i for i in manzoku_list]
        for i, manzoku in enumerate(manzoku_list2):
            if i+a >= T-1:
                break
            manzoku_list[i+a] = max(manzoku_list[i+a], manzoku+b)

    ans = max(manzoku_list) + Bmax
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0

    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    #if test:
    #    print(f"{n}C{r} = {ret}")
    return ret

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


#########################入力受付部
N, T = iip()
A = []
B = []
for i in range(N):
    a, b = iip()
    A.append(a)
    B.append(b)
Bmax = max(B)
im = B.index(Bmax)
A.pop(im)
B.pop(im)

#########################入力受付部

def main():
    manzoku_list = [0 for i in range(T)]

    for a, b in zip(A, B):
        #print(a, b)
        manzoku_list2 = [i for i in manzoku_list]
        for i, manzoku in enumerate(manzoku_list2):
            if i+a >= T:
                break
            manzoku_list[i+a] = max(manzoku_list[i+a], manzoku+b)

    ans = max(manzoku_list) + Bmax
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0

    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    #if test:
    #    print(f"{n}C{r} = {ret}")
    return ret

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


#########################入力受付部
N, T = iip()
A = []
B = []
for i in range(N):
    a, b = iip()
    A.append(a)
    B.append(b)
Bmax = max(B)
im = B.index(Bmax)
A.pop(im)
B.pop(im)

#########################入力受付部

def main():
    manzoku_list = [0 for i in range(T-1)]

    for a, b in zip(A, B):
        #print(a, b)
        manzoku_list2 = [i for i in manzoku_list]
        for i, manzoku in enumerate(manzoku_list2):
            if i+a >= T-1:
                break
            manzoku_list[i+a] = max(manzoku_list[i+a], manzoku+b)

    ans = max(manzoku_list) + Bmax
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0

    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    #if test:
    #    print(f"{n}C{r} = {ret}")
    return ret

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


#########################入力受付部
N, T = iip()
A = []
B = []
for i in range(N):
    a, b = iip()
    A.append(a)
    B.append(b)
Bmax = max(B)
im = B.index(Bmax)
A.pop(im)
B.pop(im)

#########################入力受付部

def main():
    manzoku_list = [0 for i in range(T)]

    for a, b in zip(A, B):
        #print(a, b)
        for i, manzoku in enumerate(manzoku_list.copy()):
            if i+a >= T:
                break
            manzoku_list[i+a] = max(manzoku_list[i+a], manzoku+b)

    ans = max(manzoku_list) + Bmax
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]
a.sort(key = lambda x: (x[1], x[0]))

d = [0] * (6000)
for c, v in a:
    for i in reversed(range(t)):
        d[i+c] = max(d[i+c], d[i] + v)

print(max(d))

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]
a.sort(key = lambda x: x[1], reverse = True)

d = [0] * (6000)
for c, v in a:
    for i in reversed(range(t)):
        d[i+c] = max(d[i+c], d[i] + v)

print(max(d))

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]
a.sort(key = lambda x: x[1])

d = [0] * (6000)
for c, v in a:
    for i in reversed(range(t)):
        d[i+c] = max(d[i+c], d[i] + v)

print(max(d))

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]

d = [0] * (6000)
for c, v in a:
    for i in reversed(range(t)):
        d[i+c] = max(d[i+c], d[i] + v)

print(max(d))

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]

d = [0] * (6000)
for c, v in a:
    for i in reversed(range(t)):
        d[i+c] = max(d[i+c], d[i] + v)

ans = 0
for x in d:
    ans = max(ans, x)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B


def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i, t in itertools.product(range(N), range(T)):
        u = t - A[i]
        if u >= 0:
            dp1[i+1][t] = max(dp1[i][u] + B[i], dp1[i][t])
        else:
            dp1[i+1][t] = dp1[i][t]
        u = t - A[N-1-i]
        if u >= 0:
            dp2[N-i][t] = max(dp2[N+1-i][u] + B[i], dp2[N+1-i][t])
        else:
            dp2[N-i][t] = dp2[N+1-i][t]
    v = 0
    for i, t in itertools.product(range(N), range(T)):
        v = max(v, dp1[i][t] + dp2[i+2][(T-1) - t] + B[i])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
import itertools


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i, t in itertools.product(range(N), range(T)):
        u = t - A[i]
        if u >= 0:
            dp1[i+1][t] = max(dp1[i][u] + B[i], dp1[i][t])
        else:
            dp1[i+1][t] = dp1[i][t]
        u = t - A[N-1-i]
        if u >= 0:
            dp2[N-i][t] = max(dp2[N+1-i][u] + B[1], dp2[N+1-i][t])
        else:
            dp2[N-i][t] = dp2[N+1-i][t]
    v = 0
    for i, t in itertools.product(range(N), range(T)):
        v = max(v, dp1[i][t] + dp2[i+2][(T-1) - t] + B[i])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i in range(1, N+1, 1):
        for t in range(T):
            if A[i-1] <= t:
                dp1[i][t] = max(dp1[i-1][t-A[i-1]] + B[i-1], dp1[i-1][t])
            else:
                dp1[i][t] = dp1[i-1][t]
    for i in range(N, 0, -1):
        for t in range(T):
            if A[i-1] <= t:
                dp2[i][t] = max(dp2[i+1][t-A[i-1]] + B[i-1], dp2[i+1][t])
            else:
                dp2[i][t] = dp2[i-1][t]
    v = 0
    for i in range(1, N+1, 1):
        for j in range(T):
            v = max(v, dp1[i-1][j] + dp2[i+1][(T-1) - j] + B[i-1])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
import numpy as np


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    dp1 = np.zeros((N+2, T), dtype=np.int32)
    dp2 = np.zeros((N+2, T), dtype=np.int32)
    for i in range(1, N+1, 1):
        for t in range(T):
            if A[i-1] <= t:
                dp1[i][t] = max(dp1[i-1][t-A[i-1]] + B[i-1], dp1[i-1][t])
    for i in range(N, 0, -1):
        for t in range(T):
            if A[i-1] <= t:
                dp2[i][t] = max(dp2[i+1][t-A[i-1]] + B[i-1], dp2[i+1][t])
    v = 0
    for i in range(1, N+1, 1):
        for j in range(T):
            v = max(v, dp1[i-1][j] + dp2[i+1][(T-1) - j] + B[i-1])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
import numpy as np


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    a = np.array(A, dtype=np.int32)
    b = np.array(B, dtype=np.int32)
    v = 1.0 * b / a
    order = np.argsort(v)[::-1]
    v = v[order]
    a = a[order]
    b = b[order]
    asum = np.cumsum(a)  # 時間の累積和
    bsum = np.cumsum(b)  # おいしさの累積和
    amax = 0
    bmax = 0
    bmax = 0
    for i in range(N):
        l, r = np.searchsorted(asum, [T-0.5, T + a[i] - 0.5], side='left')
        if 0 < l and l <= i:
            bmax = max(bmax, bsum[l-1] + b[i])
        if 0 < r and i < r:
            bmax = max(bmax, bsum[r-1])
    return bmax

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
import numpy as np


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    a = np.array(A, dtype=np.int32)
    b = np.array(B, dtype=np.int32)
    v = 1.0 * b / a
    order = np.argsort(v)[::-1]
    v = v[order]
    a = a[order]
    b = b[order]
    asum = np.cumsum(a)  # 時間の累積和
    bsum = np.cumsum(b)  # おいしさの累積和
    amax = 0
    bmax = 0
    bmax = 0
    for i in range(N):
        l, r = np.searchsorted(asum, [T-0.5, T + a[i]-0.5], side='left')
        if r == N:
            bmax = max(bmax, bsum[-1])
        if i == r:
            bmax = max(bmax, bsum[r] - b[i])
        if i < r < N:
            bmax = max(bmax, bsum[r] - b[i])
        if l < i:
            bmax = max(bmax, bsum[l])
    return bmax

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
import numpy as np


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    a = np.array(A, dtype=np.int32)
    b = np.array(B, dtype=np.int32)
    v = 1.0 * b / a
    order = np.argsort(v)[::-1]
    v = v[order]
    a = a[order]
    b = b[order]
    asum = np.cumsum(a)  # 時間の累積和
    bsum = np.cumsum(b)  # おいしさの累積和
    amax = 0
    bmax = 0
    bmax = 0
    for i in range(N):
        l, r = np.searchsorted(asum, [T, T + a[i]], side='left')
        if r == N:
            bmax = max(bmax, bsum[-1])
        if i == r:
            bmax = max(bmax, bsum[r] - b[i])
        if i < r < N:
            bmax = max(bmax, bsum[r] - b[i])
        if l < i:
            bmax = max(bmax, bsum[l])
    return bmax

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
n,t = map(int, input().split())
l=[list(map(int,input().split())) for i in range(n)]

MINF=-(10**10)
dp=[MINF]*(t+3333)
dp[0]=0
mx_dp=[MINF]*(t+3333)
ate_list = [[] for i in range(t+3333)]

import copy
for time in range(t):
    if dp[time] == MINF:
        continue

    mx_value = -1
    for i in range(len(l)):
        if i in ate_list[time]:
            continue
        a=l[i][0]
        b=l[i][1]

        if dp[time+a] < dp[time]+b: # update best
            dp[time+a]=dp[time]+b
            ate = copy.deepcopy(ate_list[time])
            ate.append(i)
            ate_list[time+a] = ate
            if dp[time]+b > mx_value:
                mx_value=dp[time]+b
    if mx_value >= 0:
        mx_dp[time] = mx_value

print(max(mx_dp))

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
ab=[[0]*2 for i in range(n+1)]
for i in range(1,n+1):
  ab[i][0],ab[i][1]=map(int,input().split())
dp=[[0]*(t+3001) for i in range(n+1)]
ab.sort(key=lambda x:x[0])
for i in range(1,n+1):
  for j in range(t):
    dp[i][j+ab[i][0]]=max(dp[i-1][j+ab[i][0]],dp[i-1][j]+ab[i][1])
ans=0
for i in range(n+1):
  ans=max(ans,max(dp[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
ab=[[0]*2 for i in range(n+1)]
for i in range(1,n+1):
  ab[i][0],ab[i][1]=map(int,input().split())
dp=[[0]*(t+3001) for i in range(n+1)]
ab.sort(key=lambda x:x[0])
for i in range(1,n+1):
  for j in range(t):
    dp[i][j+ab[i][0]]=max(dp[i-1][j+ab[i][0]],dp[i-1][j]+ab[i][1])
print(max(dp[n]))

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
ab=[[0]*2 for i in range(n+1)]
for i in range(1,n+1):
  ab[i][0],ab[i][1]=map(int,input().split())
dp=[[0]*(t+100000) for i in range(n+1)]
ab.sort(key=lambda x:x[0])
for i in range(1,n+1):
  for j in range(t):
    dp[i][j+ab[i][0]]=max(dp[i-1][j+ab[i][0]],dp[i-1][j]+ab[i][1])
print(max(dp[n]))

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
ab=[[0]*2 for i in range(n+1)]
for i in range(1,n+1):
  ab[i][0],ab[i][1]=map(int,input().split())
dp=[[0]*(t+100000) for i in range(n+1)]
ab.sort(key=lambda x:x[0])
for i in range(1,n+1):
  for j in range(t):
    dp[i][j+ab[i][0]]=max(dp[i-1][j+ab[i][0]],dp[i-1][j]+ab[i][1])
print(max(dp[n]))

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=lambda x: x[1])

dp = [[-1] * t for _ in range(n + 1)]
for j in range(t):
    dp[0][j] = 0

for i, (a, b) in enumerate(ab):
    for j in range(t):
        if dp[i][j] != -1:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
            if j + a <= t - 1:
                dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j] + b)

prev_t = t - 1
for i, (a, b) in enumerate(ab[::-1]):
    if dp[n-i][prev_t] == dp[n-i-1][prev_t]:
        break

    else:
        prev_t -= a

else:
    b = 0

ans = dp[n][t-1] + b
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort(key=lambda x: (x[0], x[1]))
    dp = [-1 for i in range(T*2 + 1)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T*2, 0, -1):
            if i >= a:
                if dp[i-a] >= 0 and i - a < T:
                    dp[i] = max(dp[i], dp[i-a] + b)
    for i in range(1, T*2+1):
        dp[i] = max(dp[i], dp[i-1])
    ans = dp[-1]

    # print(dp)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort()
    dp = [-1 for i in range(T*2 + 1)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T*2, 0, -1):
            if i >= a:
                if dp[i-a] >= 0 and i - a < T:
                    dp[i] = max(dp[i], dp[i-a] + b)
    for i in range(1, T*2+1):
        dp[i] = max(dp[i], dp[i-1])
    ans = dp[-1]

    # print(dp)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [tuple(map(int, input().split())) for i in range(N)]
    ans = 0
    for id in range(N):
        dp = [-1 for i in range(T + 1)]
        dp[0] = 0
        for j, t in enumerate(ab):
            if id == j:
                continue
            else:
                a, b = t
            for i in range(T, 0, -1):
                if i >= a:
                    if dp[i-a] >= 0:
                        dp[i] = max(dp[i], dp[i-a] + b)
        for i in range(1, T+1):
            dp[i] = max(dp[i], dp[i-1])
        ans = max(dp[-1] + ab[id][1], ans)
    # print(dp)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort(key=lambda x: x[1])
    ans = 0
    for id in range(N):
        dp = [-1 for i in range(T + 1)]
        dp[0] = 0
        for j in range(N):
            if id == j:
                continue
            else:
                a, b = ab[j]
            for i in range(T, 0, -1):
                if i >= a:
                    if dp[i-a] >= 0:
                        dp[i] = max(dp[i], dp[i-a] + b)
        for i in range(1, T+1):
            dp[i] = max(dp[i], dp[i-1])
        ans = max(dp[-1] + ab[id][1], ans)
    # print(dp)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort(key=lambda x: x[1])
    dp = [-1 for i in range(T*2 + 1)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T*2, 0, -1):
            if i >= a:
                if dp[i-a] >= 0 and i - a < T:
                    dp[i] = max(dp[i], dp[i-a] + b)
    for i in range(1, T*2+1):
        dp[i] = max(dp[i], dp[i-1])
    ans = dp[-1]

    # print(dp)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort(key=lambda x: x[1])
    dp = [-1 for i in range(T*2 + 1)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T*2 + 1, 0, -1):
            if i - a >= 0 and i - a < T:
                try:
                    if dp[i-a] >= 0:
                        dp[i] = max(dp[i], dp[i-a] + b)
                except:
                    print(-1)
                    exit(0)
    for i in range(1, T*2+1):
        dp[i] = max(dp[i], dp[i-1])
    ans = dp[-1]

    # print(dp)
    print(ans)


main()