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:
from collections import defaultdict
dp = defaultdict(lambda: 0)
n,t = [int(j) for j in input().split()]
lsa = []
lsb = []
dic = []
for i in range(n):
    a,b = [int(j) for j in input().split()]
    lsa.append(a)
    lsb.append(b)
    dic.append((b,a))    
dp[0,1,1] = lsb[0]
if lsa[0]>1:
    dp[0,1,0] = 0
else:
    dp[0,1,0] = lsb[0]
# dp = dict()
ans = 0
# dic.sort()
# for i in dic:
#     lsa.append(i[1])
#     lsb.append(i[0])
for i in range(n):
    for j in range(1,t+1):
        if j-lsa[i]>0:
            dp[i,j,0] = max(dp[i-1, j, 0], dp[i-1, j-lsa[i], 0]+lsb[i])
        else:
            dp[i,j,0] = dp[i-1, j, 0]
        # print(dp[i,j,0], i, j, 0)
        # print(dp[i,j], i, j)
        # dp[i,j,1] = 0
        # for k in range(1,i+1):
        dp[i,j,1] = max(dp[i-1,j,1], dp[i-1, j, 0]+lsb[i])
        # print(dp[i,j,1], i, j, 1)

print(max(dp[n-1, t, 0], dp[n-1, t, 1]))
# print(dp)

# dp = dict()
# ans = 0
# dic.sort()
# for i in dic:
#     lsa.append(i[1])
#     lsb.append(i[0])
# print(dic)

# # dp[i][t][0] <- ith dish is the last dish and maximum till
# # dp[i,t,1] <- till ith dish 


# dp.setdefault(0)
# for i in range(n):
#     for j in range(t+1):
#         # dp[i,j] = 0
#         # print(i,j)
#         ans = max(dp[i-1,0]+lsb[i], ans)
#         # if j-lsa[i]>=0:
#             # <=t-0.5:
#             dp[i,j] = max(dp[i-1,j-lsa[i]]+lsb[i], dp[i-1,j])
            
#             # print(dp[i,j], i,j, dp[i-1, j-lsa[i]], i-1, max(1,j-lsa[i]))
#         else:
#             dp[i,j] = dp[i-1,j]
# # ans = 0
# for i in range(t+1):
#     for j in range(n):
#         ans = max(dp[i,j], ans)
# print(ans)

Submission status: Wrong Answer

Solution code:
#%%
n, t = map(int, input().split())
a, b = [0] * n, [0] * n
l = [0] * n
for i in range(n):
    l[i] = list(map(int, input().split()))
l.sort()
for i in range(n):
    a[i], b[i] = l[i]
c = max(a)

dp = [[[0, -1] for _ in range(t + c + 1)] for _ in range(n)]

for i in range(n):
    if i == 0:
        dp[i][a[i]][0] = b[i]
        dp[i][a[i]][1] = a[i]
    for j in range(t + c + 1):
        tmpt = j - a[i]
        if 0 <= tmpt :
            tmpb = dp[i-1][tmpt][0] + b[i]
            if tmpb >= dp[i-1][j][0]:
                dp[i][j][1] = max(dp[i-1][tmpt][1], a[i])
            else:
                dp[i][j][1] = dp[i-1][j][1]
            dp[i][j][0] = max(dp[i-1][j][0], tmpb)
        else:
            dp[i][j] = dp[i-1][j]

ans = 0
for j in range(t + c + 1):
    if j - dp[n-1][j][1] <= t-1:
        ans = max(ans, dp[n-1][j][0])
print(ans)

Submission status: Wrong Answer

Solution code:
#%%
n, t = map(int, input().split())
a, b = [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
c = max(a)

dp = [[[0, -1] for _ in range(t + c + 1)] for _ in range(n)]

for i in range(n):
    if i == 0:
        dp[i][a[i]][0] = b[i]
        dp[i][a[i]][1] = a[i]
    for j in range(t + c + 1):
        tmpt = j - a[i]
        if 0 <= tmpt :
            tmpb = dp[i-1][tmpt][0] + b[i]
            if tmpb >= dp[i-1][j][0]:
                dp[i][j][1] = max(dp[i-1][j][1], a[i])
            dp[i][j][0] = max(dp[i-1][j][0], tmpb)
        else:
            dp[i][j] = dp[i-1][j]

ans = 0
for j in range(t + c + 1):
    if j - dp[n-1][j][1] <= t-1:
        ans = max(ans, dp[n-1][j][0])
print(ans)

Submission status: Wrong Answer

Solution code:
#%%
n, t = map(int, input().split())
#t //= 10
a, b = [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    #a[i] //= 10
    #b[i] //= 10
c = max(a)

dp = [[[0, -1] for _ in range(t + c + 1)] for _ in range(n + 1)]

for i in range(1, n+1):
    if i == 1:
        dp[i][a[i-1]][0] = b[i-1]
        dp[i][a[i-1]][1] = a[i-1]
    for j in range(t + c + 1):
        tmpt = j - a[i-1]
        if 0 <= tmpt :
            tmpb = dp[i-1][tmpt][0] + b[i-1]
            if tmpb >= dp[i-1][j][0]:
                dp[i][j][1] = max(dp[i-1][j][1], a[i-1])
            dp[i][j][0] = max(dp[i-1][j][0], tmpb)
        else:
            dp[i][j] = dp[i-1][j]

#print(dp[n])

ans = 0
for j in range(t + c + 1):
    if j - dp[n][j][1] <= t-1:
        ans = max(ans, dp[n][j][0])
print(ans)

Submission status: Wrong Answer

Solution code:
#%%
n, t = map(int, input().split())
#t //= 10
a, b = [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    #a[i] //= 10
    #b[i] //= 10

dp = [[[0, -1] for _ in range(t + max(a) + 1)] for _ in range(n + 1)]

for i in range(1, n+1):
    if i == 1:
        dp[i][a[i-1]][0] = b[i-1]
        dp[i][a[i-1]][1] = a[i-1]
    for j in range(t + max(a) + 1):
        tmpt = j - a[i-1]
        if 0 <= tmpt :
            tmpb = dp[i-1][tmpt][0] + b[i-1]
            if tmpb >= dp[i-1][j][0]:
                dp[i][j][1] = max(dp[i-1][j][1], a[i-1])
            dp[i][j][0] = max(dp[i-1][j][0], tmpb)
        else:
            dp[i][j] = dp[i-1][j]

ans = 0
for j in range(t + max(a) + 1):
    if j - dp[n][j][1] <= t-1:
        ans = max(ans, dp[n][j][0])
print(ans)

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

dp = [-1 for _ in range(T)]
dp[0] = 0
# dp[i秒の時点] := 食べ終わってる量
# 逆順に考える

answer = -1
for A, B in AB:
  for i in range(T - 1, -1, -1):
    if dp[i] != -1:
      if i + A <= T - 1:
        dp[i + A] = max(dp[i + A], dp[i] + B)
      else:
        answer = max(answer, dp[i] + B)
print(max(max(dp), answer))

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

dp = [[-1, -1] for _ in range(T + 1)]
dp[0] = [0, 0]
# dp[i秒の時点] := (食べ終わってる量, 超えて食べられる量)
# 逆順に考える

for A, B in AB:
  for i in range(T, -1, -1):
    if dp[i] != [-1, -1]:
      if i + A > T:
        dp[i][1] = max(dp[i][1], dp[i][0] + B)
      else:
        dp[i+A][0] = max(dp[i+A][0], dp[i][0] + B)
#print(dp)

answer = 0
for i in range(T):
  answer = max(max(dp[i]), answer)
answer = max(answer, dp[-1][0])
print(answer)

Submission status: Wrong Answer

Solution code:
from numpy import zeros, maximum
N, T, *AB = map(int, open(0).read().split()) 
print(AB)
dp = zeros(6010, int)
for w, v in sorted(zip(*[iter(AB)] * 2)):
  dp[w:T + w] = maximum(dp[w:T + w], dp[:T] + v)
print(dp.max())

Submission status: Wrong Answer

Solution code:
n,t = map(int,input().split())
dpa = [[0 for i in range(t)] for j in range(n+1)]
dpb = [[0 for i in range(t)] for j in range(n+1)]

for i in range(t):
   dpa[0][i] = 0
   dpb[0][i] = 0
abl = []
for _ in range(n):
   a,b = map(int,input().split())
   abl.append((a,b))

for i in range(n-1):
   for j in range(t):
      if j - abl[i][0] >= 0:
         dpa[i+1][j] = max(dpa[i][j], dpa[i][j-abl[i][0]] + abl[i][1])
      else:
         dpa[i + 1][j] = dpa[i][j]

abl = abl[::-1]
for i in range(n-1):
   for j in range(t):
      if j - abl[i][0] >= 0:
         dpb[i+1][j] = max(dpb[i][j], dpb[i][j-abl[i][0]] + abl[i][1])
      else:
         dpa[i + 1][j] = dpa[i][j]

abl = abl[::-1]
ans = 0
for i in range(t):
   for j in range(n):
      ans = max(ans, dpa[j][i]+dpb[n-j-1][t-i-1]+abl[j][1])


print(ans)

Submission status: Wrong Answer

Solution code:
n,t = map(int,input().split())
dpa = [[0 for i in range(t)] for j in range(n+1)]
dpb = [[0 for i in range(t)] for j in range(n+1)]

for i in range(t):
   dpa[0][i] = 0
   dpb[0][i] = 0
abl = []
for _ in range(n):
   a,b = map(int,input().split())
   abl.append((a,b))

for i in range(n-1):
   for j in range(t):
      if j - abl[i][0] >= 0:
         dpa[i+1][j] = max(dpa[i][j], dpa[i][j-abl[i][0]] + abl[i][1])

abl = abl[::-1]
for i in range(n-1):
   for j in range(t):
      if j - abl[i][0] >= 0:
         dpb[i+1][j] = max(dpb[i][j], dpb[i][j-abl[i][0]] + abl[i][1])
abl = abl[::-1]
ans = 0
for i in range(t):
   for j in range(n):
      ans = max(ans, dpa[j][i]+dpb[n-j-1][t-i-1]+abl[j][1])

print(ans)

Submission status: Wrong Answer

Solution code:
#Aをソートしておく，時間ギリギリにi番目の料理を頼むことで固定．
N,T = map(int,input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i],B[i] = map(int,input().split())

# T-1分以内にi番目以外の料理をできるだけ完食する
#DP1[i][t]はi番目の料理まででt分後までに完食で得られる幸福度の最大(商品番号は1から振る)


dp1 =[[0]*T for _ in range(N+1)]

for i in range(N):
    for t in range(1,T):
        dp1[i+1][t] = dp1[i][t]
        if t-A[i]>=0:
            dp1[i+1][t]=max(dp1[i][t],dp1[i][t-A[i]]+B[i])
            
ans=0
for i in range(N):
    ans=max(ans,dp1[i][-1]+B[i])
print(ans)

Submission status: Wrong Answer

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


#dp[i][j]: i番目までの料理をいくつか食べて、時間jまでに注文した美味しさの合計のmax
dp = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(n):
    for j in range(t+1):
        a, b = food[i]
        if j == t:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

        elif j + a >= t:
            dp[i+1][t] = max(dp[i][j] + b, dp[i+1][t])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

        else:
            dp[i+1][j+a] = max(dp[i][j] + b, dp[i+1][j+a])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

print(dp[n][t])

Submission status: Wrong Answer

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

food.sort()

#dp[i][j]: i番目までの料理をいくつか食べて、時間jまでに注文した美味しさの合計のmax
dp = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(n):
    for j in range(t):
        a, b = food[i]
        if j + a >= t:
            dp[i+1][t] = max(dp[i][j] + b, dp[i+1][t])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

        else:
            dp[i+1][j+a] = max(dp[i][j] + b, dp[i+1][j+a])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

print(dp[n][t])

Submission status: Wrong Answer

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

#dp[i][j]: i番目までの料理をいくつか食べて、時間jまでに注文した美味しさの合計のmax
dp = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(n):
    for j in range(t):
        a, b = food[i]
        if j + a >= t:
            dp[i+1][t] = max(dp[i][j] + b, dp[i+1][t])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

        else:
            dp[i+1][j+a] = max(dp[i][j] + b, dp[i+1][j+a])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

print(dp[n][t])

Submission status: Wrong Answer

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

#dp[i][j]: i番目までの料理をいくつか食べて、時間jまでに注文した美味しさの合計のmax
dp = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(n):
    for j in range(t+1):
        a, b = food[i]
        if j + a >= t:
            dp[i+1][t] = max(dp[i][j] + b, dp[i+1][t])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

        else:
            dp[i+1][j+a] = max(dp[i][j] + b, dp[i+1][j])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])
print(max(dp[n]))

Submission status: Wrong Answer

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

#dp[i][j]: i番目までの料理をいくつか食べて、時間jまでに注文した美味しさの合計のmax
dp = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(n):
    for j in range(t):
        a, b = food[i]
        if j + a >= t:
            dp[i+1][t] = max(dp[i][j] + b, dp[i+1][t])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

        else:
            dp[i+1][j+a] = max(dp[i][j] + b, dp[i+1][j])
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])
print(max(dp[n]))

Submission status: Wrong Answer

Solution code:
def run():
  N, T = map(int, input().split())
  ab_li = [list(map(int, input().split())) for i in range(N)]
  ab_li = sorted(ab_li, key=lambda x:x[0])
  dp = [[0 for n in range(N)] for t in range(T+1)]
  for t in range(1, T+1):
    A, B = ab_li[0]
    if A <= t:
      dp[t][0] = B
  for t in range(1, T):
    for n in range(1, N):
      A, B = ab_li[n]
      if A > t: continue
      dp[t][n] = max(dp[t][n-1], B+dp[t-A][n-1])
  for n in range(1, N):
    A, B = ab_li[n]
    dp[T][n] = max(dp[T][n-1], B+dp[T-1][n-1])
  print(dp[-1][-1])
  
if __name__ == '__main__':
  run()

Submission status: Wrong Answer

Solution code:
def run():
  N, T = map(int, input().split())
  ab_li = [list(map(int, input().split())) for i in range(N)]
  ab_li = sorted(ab_li, key=lambda x:x[0], reverse=True)
  dp = [[0 for n in range(N)] for t in range(T+1)]
  for t in range(1, T+1):
    A, B = ab_li[0]
    if A <= t:
      dp[t][0] = B
  for t in range(1, T):
    for n in range(1, N):
      A, B = ab_li[n]
      if A > t: continue
      dp[t][n] = max(dp[t][n-1], B+dp[t-A][n-1])
  for n in range(1, N):
    A, B = ab_li[n]
    dp[T][n] = max(dp[T][n-1], B+dp[T-1][n-1])
  print(dp[-1][-1])
  
if __name__ == '__main__':
  run()

Submission status: Wrong Answer

Solution code:
def run():
  N, T = map(int, input().split())
  ab_li = [list(map(int, input().split())) for i in range(N)]
  ab_li = sorted(ab_li, key=lambda x:x[0])
  dp = [[0 for n in range(N)] for t in range(T+1)]
  for t in range(1, T+1):
    if ab_li[0][0] <= t:
      dp[t][0] = ab_li[0][1]
  for t in range(1, T):
    for n in range(1, N):
      A, B = ab_li[n]
      if A > t: continue
      dp[t][n] = max(dp[t][n-1], B+dp[t-A][n-1])
  for n in range(1, N):
    A, B = ab_li[n]
    dp[T][n] = max(dp[T][n-1], B+dp[T-1][n-1])
  print(dp[-1][-1])
  
if __name__ == '__main__':
  run()

Submission status: Wrong Answer

Solution code:
N,T = map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)

inf=0
dp=[[inf for i in range(T+1)] for j in range(N+1)]
for i in range(T+1): dp[0][i]=0

A.sort()
#B.sort(reverse=True)

for i in range(N):
    for j in range(T):
        if j > T:
            break
        if j>=A[i]:
            dp[i+1][j] = max(dp[i][j-A[i]] + B[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
        

print(dp[N-1][T-1] + B[N-1])

Submission status: Wrong Answer

Solution code:
N,T = map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)

inf=0
dp=[[inf for i in range(T+1)] for j in range(N+1)]
for i in range(T+1): dp[0][i]=0

A.sort()

for i in range(N):
    for j in range(T):
        if j>=A[i]:
            dp[i+1][j] = max(dp[i][j-A[i]] + B[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
#print(B[N-1])
print(dp[N-1][T-1] + B[N-1])

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
dp=[0]*(t+1)

for i in range(n):
    dp_sub=[0]*(t+1)
    for j in range(t):
        if j==0 and ab[i][0]<=t:
            #print(ab[i][1])
            dp_sub[ab[i][0]]=ab[i][1]
        else:
            if dp[j]!=0 and j+ab[i][0]<=t:
                #print(ab[i][0])
                #print()
                dp_sub[j+ab[i][0]]=dp[j]+ab[i][1]
    for j in range(t):
        dp[j]=max(dp[j],dp_sub[j])
print(max(dp))

Submission status: Wrong Answer

Solution code:
n,t = map(int, input().split())
ls = [list(map(int, input().split())) for i in range(n)]
t-=1
ls.sort(key=lambda x: x[1], reverse=True)
ls.sort(key=lambda x: x[0], reverse=False)
dp = [[0 for _ in range(t+1)] for _ in range(n+1)]
ans= 0
for i in range(n+1):
    for j in range(t+1):
        if i>0 and j>=ls[i-1][0]:
            if dp[i-1][j-ls[i-1][0]] + ls[i-1][1]>dp[i-1][j]:
                dp[i][j] =dp[i-1][j-ls[i-1][0]] + ls[i-1][1]
                ans = max(dp[i][j], ans)
            else:
                dp[i][j] = dp[i-1][j]
                ans = max(dp[i][j]+ls[i-1][1], ans)

        elif i>0:
            dp[i][j] = dp[i-1][j]
            ans = max(dp[i][j]+ls[i-1][1], ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def solve(n, t, a, b):
    dp = np.zeros(t, dtype=int)
    candidates = []
    for w, v in zip(a, b):
        candidates.append(dp[-1] + v)
        if w > t:
            continue
        dp[w:] = np.maximum(dp[:-w] + v, dp[w:])
    return np.max(candidates)

n, t = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, t, a, b))

Submission status: Wrong Answer

Solution code:
N,T=map(int,input().split())
import numpy as np
dp=np.zeros(T,dtype=int)
maxval=0

meals=[None]*N
for i in range(N):
  a,b=map(int,input().split())
  meals[i]=a,b

meals=sorted(meals,key=lambda x:x[1])

for i in range(N):
  a,b=meals[i]
  if maxval<dp[-1]+b:
    maxval=dp[-1]+b
  np.maximum(dp[:-a]+b,dp[a:],out=dp[a:])
  
print(maxval)

Submission status: Wrong Answer

Solution code:
N,T=map(int,input().split())
import numpy as np
dp=np.zeros(T,dtype=int)
maxval=0
for i in range(N):
  a,b=map(int,input().split())
  if maxval<dp[-1]+b:
    maxval=dp[-1]+b
  np.maximum(dp[:-a]+b,dp[a:],out=dp[a:])
  
print(maxval)

Submission status: Wrong Answer

Solution code:
n, T = map(int, input().split())

foods = []

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

dp = [0] * 6001

for a, b in foods:
    for t in range(6000, a-1, -1):
        if t - a < T:
        	dp[t] = max(dp[t], dp[t-a] + b)
print(max(dp))

Submission status: Wrong Answer

Solution code:
n, T = map(int, input().split())

foods = []

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

dp = [0] * 6005

for a, b in foods:
    for t in range(6000, a-1, -1):
        if t - a >= T:
            x = 0
        else:
            x = dp[t-a]
        dp[t] = max(dp[t], x + b)
print(max(dp))

Submission status: Wrong Answer

Solution code:
n, T = map(int, input().split())

foods = []

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

dp = [0] * 6001

for a, b in foods:
    for t in range(6000, a-1, -1):
        if t - a >= T:
            x = 0
        else:
            x = dp[t-a]
        dp[t] = max(dp[t], x + b)
print(max(dp))

Submission status: Wrong Answer

Solution code:
n, t = map(int, input().split())
prs = list(list(map(int, input().split())) for _ in range(n))
prs = sorted(prs, reverse=True, key=lambda x:x[1])
res, i = 0, 0
while t > 0 and i < n:
    res += prs[i][1]
    t -= prs[i][0]
    i += 1
print(res)

Submission status: Wrong Answer

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    N, T = map(int, f_i.readline().split())
    AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
    AB.sort()
    
    dp = [[0] * T for i in range(N + 1)]
    
    for i, AB_i in enumerate(AB, start=1):
        A_i, B_i = AB_i
        dp_i = dp[i]
        dp_pre = dp[i-1]
        for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i):
            x, y = t
            if x < y + B_i:
                dp_i[j] = y + B_i
            else:
                dp_i[j] = x
    
    ans = max(dp[k][-1] + AB[k][1] for k in range(N))
    ans = max(ans, dp[-1][-1])
    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    N, T = map(int, f_i.readline().split())
    AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
    AB.sort()
    
    dp = [[0] * T for i in range(N + 1)]
    
    for i, AB_i in enumerate(AB, start=1):
        A_i, B_i = AB_i
        dp_i = dp[i]
        dp_pre = dp[i-1]
        for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i):
            x, y= t
            if x < y + B_i:
                dp_i[j] = y + B_i
            else:
                dp_i[j] = x
    
    ans = max(dp[k][-1] + AB[k][1] for k in range(N))
    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    N, T = map(int, f_i.readline().split())
    AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
    AB.sort()
    
    dp = [[0] * T for i in range(N + 1)]
    
    for i, AB_i in enumerate(AB, start=1):
        A_i, B_i = AB_i
        dp_i = dp[i]
        dp_pre = dp[i-1]
        for j in range(A_i, T):
            dp_i[j] = max(dp_pre[j], dp_pre[j-A_i] + B_i)
    
    ans = max(dp[k][-1] + AB[k][1] for k in range(N))
    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    N, T = map(int, f_i.readline().split())
    AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
    AB.sort()
    
    dp = [[0] * T for i in range(N + 1)]
    
    for i, AB_i in enumerate(AB, start=1):
        A_i, B_i = AB_i
        for j in range(A_i, T):
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-A_i] + B_i)
    
    ans = max(dp[k][-1] + AB[k][1] for k in range(N))
    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
from sys import stdin
f_i = stdin

N, T = map(int, f_i.readline().split())
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()

dp = [[0] * T for i in range(N + 1)]

for i, AB_i in enumerate(AB, start=1):
    A_i, B_i = AB_i
    for j in range(A_i, T):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-A_i] + B_i)

ans = max(dp[k][T-1] + AB[k][1] for k in range(N))
print(ans)

Submission status: Wrong Answer

Solution code:
def p_e():
    n, t = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    dp = [0] * (t + 1)
    for i in range(n):
        w, v = ab[i]
        next = [0] * (t + 1)
        for j in range(t):
            next[min(t, j + w)] = max(dp[j] + v, dp[min(t, j + w)])
        dp = next
    print(dp[-1])


if __name__ == '__main__':
    p_e()

Submission status: Wrong Answer

Solution code:
def p_e():
    n, t = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x: x[1])
    dp = [0] * t
    for i in range(n):
        w, v = ab[i]
        next = [0] * t
        for j in range(t - 1):
            next[min(t - 1, j + w)] = max(dp[j] + v, dp[min(t - 1, j + w)])
        dp = next
    print(dp[-1])

if __name__ == '__main__':
    p_e()

Submission status: Wrong Answer

Solution code:
def p_e():
    n, t = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    dp = [0] * t
    for i in range(n):
        w, v = ab[i]
        next = [0] * t
        for j in range(t - 1):
            next[min(t - 1, j + w)] = max(dp[j] + v, dp[min(t - 1, j + w)])
        dp = next
    print(dp[-1])


if __name__ == '__main__':
    p_e()

Submission status: Wrong Answer

Solution code:
N, T = map(int, input().split())
p = []
for i in range(N):
    A, B = map(int, input().split())
    p.append([A, B])
sorted(p)

dp = [[0]*3005 for _ in range(3005)]
ans = 0
for i in range(N):
    for j in range(T):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        nextj = j + p[i][0]
        if nextj < T:
            dp[i+1][nextj] = max(dp[i+1][nextj], dp[i][j] + p[i][1])
    now = dp[i][T-1] + p[i][1]
    ans = max(ans, now)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy

n,t = map(int,input().split())
a = []
b = []

for i in range(n):
  tmp1,tmp2 = map(int,input().split())
  a.append(tmp1)
  b.append(tmp2)

array = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(len(a)):
  for j in range(t):
    array[i+1][j] = max(array[i+1][j],array[i][j])
    
    index = min(j+a[i], t)
    array[i+1][index] = max(array[i][j] + b[i],array[i+1][index])
    
  array[i+1][t] = max(array[i+1][t],array[i][t])

print(max(array[n]))

Submission status: Wrong Answer

Solution code:
import copy

n,t = map(int,input().split())
a = []
b = []

for i in range(n):
  tmp1,tmp2 = map(int,input().split())
  a.append(tmp1)
  b.append(tmp2)

array = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(len(a)):
  for j in range(t):
    array[i+1][j] = max(array[i+1][j],array[i][j])
    
    index = min(j+a[i], t)
    array[i+1][index] = max(array[i][j] + b[i],array[i+1][index])

print(max(array[n]))

Submission status: Wrong Answer

Solution code:
import copy

n,t = map(int,input().split())
a = []
b = []

for i in range(n):
  tmp1,tmp2 = map(int,input().split())
  a.append(tmp1)
  b.append(tmp2)

que = {0}
array = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(len(a)):
  copy_que = copy.deepcopy(que)
  
  for q in que:
    array[i+1][q] = max(array[i][q],array[i+1][q])
    if (q + a[i]) >= t:
      array[i+1][t] = max(array[i][t], array[i][q] + b[i],array[i+1][t])
    else:
      array[i+1][q+a[i]] = max(array[i][q+a[i]], array[i][q] + b[i],array[i+1][q+a[i]])
      copy_que.add(q+a[i])
  
  que = copy.deepcopy(copy_que)
  
print(max(array[n]))

Submission status: Wrong Answer

Solution code:
import copy

n,t = map(int,input().split())
a = []
b = []

for i in range(n):
  tmp1,tmp2 = map(int,input().split())
  a.append(tmp1)
  b.append(tmp2)

que = {0}
array = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(len(a)):
  for j in range(t):
    array[i+1][j] = max(array[i+1][j],array[i][j])
    
    index = min(j+a[i], t)
    array[i+1][index] = max(array[i][index],array[i][j] + b[i],array[i+1][index])

print(max(array[n]))

Submission status: Wrong Answer

Solution code:
import copy

n,t = map(int,input().split())
a = []
b = []

for i in range(n):
  tmp1,tmp2 = map(int,input().split())
  a.append(tmp1)
  b.append(tmp2)

que = {0}
array = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(len(a)):
  for j in range(t):
    array[i+1][j] = max(array[i+1][j],array[i][j])
    
    index = min(j+a[i], t)
    array[i+1][index] = max(array[i][index],array[i][j] + b[i])

print(max(array[n]))

Submission status: Wrong Answer

Solution code:
import copy

n,t = map(int,input().split())
a = []
b = []

for i in range(n):
  tmp1,tmp2 = map(int,input().split())
  a.append(tmp1)
  b.append(tmp2)

que = {0}
array = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(len(a)):
  copy_que = copy.deepcopy(que)
  
  for q in que:
    array[i+1][q] = max(array[i][q],array[i+1][q])
    if (q + a[i]) >= t:
      array[i+1][t] = max(array[i][t], array[i][q] + b[i])
    else:
      array[i+1][q+a[i]] = max(array[i][q+a[i]], array[i][q] + b[i])
      copy_que.add(q+a[i])
  
  que = copy.deepcopy(copy_que)
  
print(max(array[n]))

Submission status: Wrong Answer

Solution code:
import copy

n,t = map(int,input().split())
a = []
b = []

for i in range(n):
  tmp1,tmp2 = map(int,input().split())
  a.append(tmp1)
  b.append(tmp2)

que = {0}
array = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(len(a)):
  for j in range(t):
    array[i+1][j] = max(array[i+1][j],array[i][j])
    
    index = min(j+a[i], t)
    array[i+1][index] = max(array[i][index],array[i][j] + b[i])


for i in array:
  print(i)
  
print(max(array[n]))

Submission status: Wrong Answer

Solution code:
import numpy as np

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 = np.array([0]*t)
ans = 0
for a,b in ab:
    ans = max(ans,dp[-1]+b)
    dp[a:] = np.maximum(dp[:-a]+b,dp[a:])
# print(dp,ans)
print(max(ans,dp[-1]))

Submission status: Wrong Answer

Solution code:
import itertools

N,T = map(int, input().split())
X = [[]*2]*N
t = 0
for i in range(N):
  X[i] = list(map(int, input().split()))
if sum([x[0] for x in X]) <= T - 1:
  print(sum([x[1] for x in X]))
  exit()
X.sort()

ANS = 0
for x in itertools.permutations(X):
  ans = 0
  t = T
  for i in x:
    t -= i[0]
    ans += i[1]
    if t <= 1:
      break
  if ans > ANS: ANS = ans
      
print(ANS)

Submission status: Wrong Answer

Solution code:
import itertools

N,T = map(int, input().split())
X = [[]*2]*N
t = 0
for i in range(N):
  X[i] = list(map(int, input().split()))
if sum([x[0] for x in X]) <= T:
  print(sum([x[1] for x in X]))
  exit()
X.sort()

ANS = 0
for x in itertools.permutations(X):
  ans = 0
  t = T
  for i in x:
    t -= i[0]
    ans += i[1]
    if t <= 1:
      break
  if ans > ANS: ANS = ans
      
print(ANS)

Submission status: Wrong Answer

Solution code:
import itertools

N,T = map(int, input().split())
X = [[]*2]*N
for i in range(N):
  X[i] = list(map(int, input().split()))
X.sort()
X.reverse()

ANS = 0
for x in itertools.permutations(X):
  ans = 0
  t = T
  for i in x:
    t -= i[0]
    ans += i[1]
    if t <= 1:
      break
  if ans > ANS: ANS = ans
      
print(ANS)

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
dp=[[-1 for j in range(2)] for i in range(t+1)]
dp[0][0]=0
d=[]
for i in range(n):
    d.append(list(map(int,input().split())))
for i in range(n):
    for j in range(t,-1,-1):
        for k in range(1,-1,-1):
            if k==0:
                if dp[j][k]>=0 and j+d[i][0]<=t:
                    dp[j+d[i][0]][k]=max(dp[j+d[i][0]][k],dp[j][k]+d[i][1])
            if k==1:
                if dp[j][0]>=0:
                    dp[j][k]=max(dp[j][k],dp[j][0]+d[i][1])
ans=0
for i in range(t+1):
    for j in range(2):
        ans=max(ans,dp[i][j])
print(ans)

Submission status: Wrong Answer

Solution code:
n,t=map(int,input().split())
dp=[[-1 for j in range(2)] for i in range(t+1)]
dp[0][0]=0
d=[]
for i in range(n):
    d.append(list(map(int,input().split())))
for i in range(n):
    for j in range(t,-1,-1):
        for k in range(1,-1,-1):
            if k==0:
                if dp[j][k]>=0 and j+d[i][0]<t:
                    dp[j+d[i][0]][k]=max(dp[j+d[i][0]][k],dp[j][k]+d[i][1])
            if k==1:
                if dp[j][0]>=0:
                    dp[j][k]=max(dp[j][k],dp[j][0]+d[i][1])
ans=0
for i in range(t+1):
    for j in range(2):
        ans=max(ans,dp[i][j])
print(ans)