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: Runtime Error

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())

dp = [[-1] * (t+1) for i in [0] * n]
def dfs(i, l):
  if(i == n or l <= 0):
    return 0
  elif(dp[i][l] != -1):
    return dp[i][l]
  else:
    dp[i][l] = max(b[i] + dfs(i+1, l - a[i]), dfs(i+1, l))
    return dp[i][l]

print(dfs(0, t))

Submission status: Runtime Error

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

AB.sort()
dp = [0] * T
#print("AB:", AB)

answer = 0
for a, b in AB:
  for t in range(T-1, -1, -1):
    if dp[t]:
      if  a + t < T:
        dp[a + t] = max(dp[a + t], dp[t] + b)
        answer = max(answer, dp[a + t])
      else:
        answer = max(answer, dp[t] + b)
  if a < T:
    dp[a] = max(dp[a], b)
  answer = max(answer, b)
  #print("dp:", dp)
print(answer)      N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()
dp = [0] * T
#print("AB:", AB)

answer = 0
for a, b in AB:
  for t in range(T-1, -1, -1):
    if dp[t]:
      if  a + t < T:
        dp[a + t] = max(dp[a + t], dp[t] + b)
        answer = max(answer, dp[a + t])
      else:
        answer = max(answer, dp[t] + b)
  if a < T:
    dp[a] = max(dp[a], b)
  answer = max(answer, b)
  #print("dp:", dp)
print(answer)

Submission status: Runtime Error

Solution code:
def solve():
    from sys import stdin
    #f_i = stdin
    f_i = open('ABC_145_E_in_s4')#
    
    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: Runtime Error

Solution code:
def solve():
    from sys import stdin
    #f_i = stdin
    f_i = open('ABC_145_E_in_s3')#
    
    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: Runtime Error

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

arr = [0]*n
add = 0
for i in range(n):
	a, b = map(int, input().split())
	arr[i] = [a, b]
	add += b

dp = {}
def solve(i, rem, total):
	if (i, rem, total) in dp:
		return dp[(i, rem, total)]
	if i==n:
		return total
	if rem > 0:
		ans = max(solve(i+1, rem-arr[i][0], total + arr[i][1]), solve(i+1, rem, total))
	else:
		ans = solve(i+1, rem, total)
	dp[(i, rem, total)]  = ans
	return ans
ans = solve(0, t, 0)
print(ans)

Submission status: Runtime Error

Solution code:
N, T = list(map(int, input().split(" ")))

# knapsack problem
weights = [] # weights are time, with limit T
values = [] # value is happiness
for i in range(0, N):
    # dish i has processing time (weight) A and deliciousness (value) B
    A,B = list(map(int, input().split(" ")))
    weights.append(A)
    values.append(B)

# m[i,w] will store the maximum possible happiness value that can be attained within time w<T using only dishes up to i
W = T-1
#m = [[0] * W for _ in range(N)]
m = [[0 for _ in range(W)] for _ in range(N)]
#dishes = [[[]] * W for _ in range(N)]
dishes = [[[] for _ in range(W)] for _ in range(N)]

for j in range(0, W):
    m[0][j] = 0

for i in range(0, N):
    for j in range(0, W):
        if weights[i] > j:
            m[i][j] = m[i-1][j]
            dishes[i][j] = dishes[i-1][j].copy()
        else:
            m[i][j] = max(m[i-1][j], m[i-1][j-weights[i]] + values[i])

            if (m[i-1][j-weights[i]] + values[i]) > m[i-1][j]:
                dishes[i][j] = dishes[i-1][j-weights[i]].copy()
                dishes[i][j].append(i)
            else:
                dishes[i][j] = dishes[i-1][j].copy()

#for row in m:
#    print(row)

#for row in dishes:
#    print(row)
optimal_dishes = dishes[N-1][W-1]
remaining_values = [values[i] for i in range(N) if not(i in optimal_dishes)]
maximal_value = max(remaining_values)

print(m[N-1][W-1] + maximal_value)

Submission status: Runtime Error

Solution code:
import numpy as np
n,t=map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
dp = [0]*t
ans = 0
eaten = []
for a,b in ab: # a:時間 b:満足度
    if max(dp)+b>ans:
        dpmax = dp.index(max(dp))
        if dpmax+a<=t-1:
            ans = max(max(dp)+b,ans)
            dp[dpmax+a] = ans
            eaten.append([a,b])
x = np.setdiff1d((np.array(ab)).T[1],(np.array(eaten)).T[1])
print(int(ans)+max(x)) if len(x)>0 else print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n,t=map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
dp = [0]*t
ans = 0
eaten = []
for a,b in ab: # a:時間 b:満足度
    if max(dp)+b>ans:
        dpmax = dp.index(max(dp))
        if dpmax+a<=t-1:
            ans = max(max(dp)+b,ans)
            dp[dpmax+a] = ans
            eaten.append([a,b])
x = np.union1d((np.array(ab)).T[1],(np.array(eaten)).T[1])
print(int(ans)+max(x))

Submission status: Runtime Error

Solution code:
import numpy as np
n,t=map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
dp = np.zeros((n,t))
def DP(i,j):
    ans=0
    if i>=n: return 0
    else:
        if dp[i][j]>0:
            return dp[i][j]
        elif 0>=j:
            return DP(i+1,j)
        else:
            dp[i][j] = max(DP(i+1,j-ab[i][0])+ab[i][1],DP(i+1,j))
            return dp[i][j]
ans = DP(0,t-1)
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n,t=map(int,input().split())
ab=[]
a=0
for i in range(n):
    ab.append(list(map(int,input().split())))
    a += ab[i][0]
sorted(ab)
dp = np.zeros((n,max(a,t)))
def DP(i,j):
    ans=0
    if i>=n: return 0
    else:
        if dp[i][j]>0:
            return dp[i][j]
        elif 0>=j:
            return DP(i+1,j)
        else:
            dp[i][j] = max(DP(i+1,j-ab[i][0])+ab[i][1],DP(i+1,j))
            return dp[i][j]
ans = DP(0,t-1)
print(int(ans))

Submission status: Runtime Error

Solution code:
N, W = map(int, input().split())
items = sorted([list(map(int, input().split())) for i in range(N)])

# dp1[i][j] := 商品0 ~ i が対象
dp = [[0] * (W + 1) for i in range(N + 1)]

# dpテーブルを埋める
for i in range(N):
    wi, vi = items[i]
    for j in range(W + 1):
        if j + wi <= W:
            dp[i + 1][j + wi] = max(dp[i + 1][j + wi], dp[i][j] + vi)
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])


ans = 0
for i, (wi, vi) in enumerate(items):
    for j in range(W):
        ans = max(ans, dp[i] + vi)

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8

N, T = (int(x) for x in input().split())
food = [list(map(int, input().split())) for i in range(N)]
max_satisfaction = []
satis = time = 0

def findmax(food, ms, mt, foodnum):
    #print("foodnum:", foodnum, ", len(food)", len(food))
    for i in range(len(food)):
        foodlist = food[:]
        #print("i:", i, ", len:", len(foodlist))
        #print(", foodlist:", foodlist)
        mtdash = mt + foodlist[i][0]
        msdash = ms + foodlist[i][1]
        del foodlist[i]
        #print("mtdash:",mtdash, "msdash:", msdash)
        if mtdash<T:
            if len(foodlist)>0:
                #print("call findmax:", mtdash)
                findmax(foodlist, msdash, mtdash, i)
            else:
                #print("over!", mtdash)
                max_satisfaction.append(msdash)
        else:
            #print("over!", mtdash)
            max_satisfaction.append(msdash)

findmax(food, satis, time, 0)
print(max(max_satisfaction))

Submission status: Runtime Error

Solution code:
# coding: utf-8

N, T = (int(x) for x in input().split())
food = [list(map(int, input().split())) for i in range(N)]
max_satisfaction = []
satis = time = 0

def findmax(food, ms, mt, foodnum):
    #print("foodnum:", foodnum, ", len(food)", len(food))
    for i in range(len(food)):
        foodlist = food[:]
        #print("i:", i, ", len:", len(foodlist))
        #print(", foodlist:", foodlist)
        mtdash = mt + foodlist[i][0]
        msdash = ms + foodlist[i][1]
        del foodlist[i]
        if mtdash<T and len(foodlist)>0:
        #    print("call findmax:", mtdash)
            findmax(foodlist, msdash, mtdash, i)
        elif len(foodlist)>0:
        #    print("over!", mtdash)
            max_satisfaction.append(msdash)

findmax(food, satis, time, 0)
print(max(max_satisfaction))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(3000)

import numpy as np
N, T = [int(a) for a in input().split()]
time = np.full(N + 1, -1, dtype = np.int32)
value = np.full(N + 1, -1, dtype = np.int32)
for i in range(1, N + 1):
    time[i], value[i] = [int(a) for a in input().split()]

# Sort the array in the increasing order of value
time = time[np.argsort(value)]
value.sort()

# table for knapsack problem
# maximum possible time is T-1
dp_table = np.full((N + 1, T + 1), -1, dtype = np.int32)

def knapsack(n, t):
    '''
    Input: n ... the number of elements to choose from
                 n means items 1, 2, ..., n can be chosen
           t ... time limit
    Output: total value
    '''
    if n <= 0 or t <= 0:
        return 0
    elif dp_table[n, t] >= 0:
        return dp_table[n, t]
    elif time[n] > t:
        ans = knapsack(n-1, t)
    else:
        ans = max(knapsack(n-1, t), value[n] + knapsack(n-1, t - time[n]))

    dp_table[n, t] = ans
    return ans

def all_you_can_eat(n, t):
    if n <= 0 or t <= 0:
        return 0
    else:
        # Eat the most delicious food at the beginning
        tmp1 = value[n] + all_you_can_eat(n - 1, t - time[n])
        # Eat the most delicious food at the end
        tmp2 = value[n] + knapsack(n - 1, t - 1)
        return max(tmp1, tmp2)

print(all_you_can_eat(N, T))

Submission status: Runtime Error

Solution code:
import numpy as np
N, T = [int(a) for a in input().split()]
time = np.full(N + 1, -1, dtype = np.int32)
value = np.full(N + 1, -1, dtype = np.int32)
for i in range(1, N + 1):
    time[i], value[i] = [int(a) for a in input().split()]

# Sort the array in the increasing order of value
time = time[np.argsort(value)]
value.sort()

# table for knapsack problem
# maximum possible time is T-1
dp_table = np.full((N + 1, T + 1), -1, dtype = np.int32)

def knapsack(n, t):
    '''
    Input: n ... the number of elements to choose from
                 n means items 1, 2, ..., n can be chosen
           t ... time limit
    Output: total value
    '''
    if n <= 0 or t <= 0:
        return 0
    elif dp_table[n, t] >= 0:
        return dp_table[n, t]
    elif time[n] > t:
        ans = knapsack(n-1, t)
    else:
        ans = max(knapsack(n-1, t), value[n] + knapsack(n-1, t - time[n]))

    dp_table[n, t] = ans
    return ans

def all_you_can_eat(n, t):
    if n <= 0 or t <= 0:
        return 0
    else:
        # Eat the most delicious food at the beginning
        tmp1 = value[n] + all_you_can_eat(n - 1, t - time[n])
        # Eat the most delicious food at the end
        tmp2 = value[n] + knapsack(n - 1, t - 1)
        return max(tmp1, tmp2)

print(all_you_can_eat(N, T))

Submission status: Runtime Error

Solution code:
n, t = map(int, input().split(' '))
tmp_food_table = []
for _ in range(n):
    tmp_food_table.append(tuple(map(int, input().split(' '))))
food_table = []
for i in tmp_food_table:
    food_table.append((i[0],i[1],i[1]/i[0]))
food_table = sorted(food_table,key=lambda x:x[0],reverse=False)
t = t - 1
current_t = 0
result = 0
tmp_list = [i for i in range(len(food_table))]
s = len(tmp_list)
while True:
    tmp = []
    for i in tmp_list:
        tmp.append(food_table[i])
    current_item = max(tmp,key=lambda x:x[2])
    if current_t + current_item[0] < t:
        tmp_list.remove(food_table.index(current_item))
        result = result + current_item[1]
        current_t = current_t + current_item[0]
    if s == len(tmp_list) :
        result = result + current_item[1]
        break
    if len(tmp_list) == 0:
        break
    s = len(tmp_list)
print(result)

Submission status: Runtime Error

Solution code:
n, t = map(int, input().split(' '))
tmp_food_table = []
for _ in range(n):
    tmp_food_table.append(tuple(map(int, input().split(' '))))
food_table = []
for i in tmp_food_table:
    food_table.append((i[0],i[1]))
food_table = sorted(food_table,key=lambda x:x[0],reverse=False)
t = t - 1
current_t = 0
result = 0
tmp_list = [i for i in range(len(food_table))]
s = len(tmp_list)
while True:
    tmp = []
    for i in tmp_list:
        tmp.append(food_table[i])
    current_item = max(tmp,key=lambda x:x[1])
    if current_t + current_item[0] < t:
        tmp_list.remove(food_table.index(current_item))
        result = result + current_item[1]
        current_t = current_t + current_item[0]
    if s == len(tmp_list) :
        result = result + current_item[1]
        break
    if len(tmp_list) == 0:
        break
    s = len(tmp_list)
print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
N,T=map(int,input().split())
cap=[0]*(N+1)
value=[0]*(N+1)
maxvalue=[[-1 for i in range(T)] for j in range(N+1)]
choice=[0]*(N+1)
for i in range(1,N+1):
  cap[i],value[i]=map(int,input().split())
def backpack(i,c):
  if i==0:
    return 0
  if c-cap[i]<0:
    if maxvalue[i][c]== -1:
      maxvalue[i][c]=backpack(i-1,c) 
    return maxvalue[i][c]
  else:
    if maxvalue[i][c]== -1:
      a=backpack(i-1,c)
      b=backpack(i-1,c-cap[i])+value[i]
      if a>b:
        maxvalue[i][c]=a
      else:
        maxvalue[i][c]=b
    return maxvalue[i][c]
if __name__ == '__main__':
  maxv=backpack(N,T-1)
  for i in range(N):
    if maxvalue[N-i][T-1]>maxvalue[N-i-1][T-1]:
      choice[N-i]=1
      T=T-cap[N-i]
  l=[[choice[i],value[i]] for i in range(N+1)]
  l.sort(key=lambda x: x[1])
  for i in range(N+1):
    if l[N-i][0]==0:
      print(maxv+l[N-i][1])
      break

Submission status: Runtime Error

Solution code:
import numpy as np

N, T = map(int, input().split())
A = np.zeros([N],dtype=np.int32)
B = np.zeros([N],dtype=np.int32)
for i in range(N):
    A[i],B[i] = map(int, input().split())

Ai = np.argsort(A)
A = A[Ai]
B = B[Ai]

DP = np.full([N,T],-1)

def rec_dp(i, lim):
    global N, DP, A2, B2
    if DP[i][lim] != -1 :
        return DP[i][lim]
    if i==N-1:
        res = 0
    elif lim < A2[i]:
        res = rec_dp(i+1, lim)
    else:
        res = max(rec_dp(i+1, lim-A2[i])+B2[i], rec_dp(i+1, lim))
    
    DP[i][lim] = res
    return res
   
ans2 = 0
for i in range(1,N):
    A2 = A[0:i-1]
    B2 = B[0:i-1]
    ans = rec_dp(0,T-1) + B[i]
    if ans2 < ans:
        ans2 = ans

print(int(ans2))

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = list(zip(A, B))
# 食べるのにかかる時間で昇順にソート
ls.sort()
# 上の並び順において、ls[i:]の美味しさの最大値をdeli[i]とする
# deli = [0]*N
# deli[- 1] = ls[-1][- 1]
deli = [ls[- 1][- 1]]
for i in range(N - 2, - 1, - 1):
    #deli[i] = max(deli[i - 1], ls[i][- 1])
    deli.append(max(deli[i - 1], ls[i][- 1]))
    
deli = deli[::- 1]

res = 0
dp = [0]*T
for i in range(N - 1):
    for j in range(T - 1, - 1, - 1):
        if ls[i][0] <= j:
            dp[j] = max(dp[j], dp[j - ls[i][0]] + ls[i][1])
    res = max(res, dp[- 1] + deli[i + 1])
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
N, T = [int(a) for a in input().split()]
time = np.full(N + 1, -1)
value = np.full(N + 1, -1)
for i in range(1, N + 1):
    time[i], value[i] = [int(a) for a in input().split()]

# Sort the array in the increasing order of value
time = time[np.argsort(value)]
value.sort()

# table for knapsack problem
# maximum possible time is T-1
dp_table = np.full((N + 1, T + 1), -1)

def knapsack(n, t):
    '''
    Input: n ... the number of elements to choose from
                 n means items 1, 2, ..., n can be chosen
           t ... time limit
    Output: total value
    '''
    if n <= 0 or t <= 0:
        return 0
    elif dp_table[n, t] >= 0:
        return dp_table[n, t]
    elif time[n] > t:
        ans =  knapsack(n-1, t)
    else:
        ans = max(knapsack(n-1, t), value[n] + knapsack(n-1, t - time[n]))

    dp_table[n, t] = ans
    return ans

def all_you_can_eat(n, t):
    if n <= 0 or t <= 0:
        return 0
    else:
        # Eat the most delicious food at the beginning
        tmp1 = value[n] + all_you_can_eat(n - 1, t - time[n])
        # Eat the most delicious food at the end
        tmp2 = value[n] + knapsack(n - 1, t - 1)
        return max(tmp1, tmp2)

print(int(all_you_can_eat(N, T)))

Submission status: Runtime Error

Solution code:
import numpy as np
N, T = [int(a) for a in input().split()]
time = np.full(N + 1, -1)
value = np.full(N + 1, -1)
for i in range(1, N + 1):
    time[i], value[i] = [int(a) for a in input().split()]

# Sort the array in the increasing order of value
time = time[np.argsort(value)]
value.sort()

# table for knapsack problem
# maximum possible time is T-1
dp_table = np.full((N + 1, T + 1), -1)

def knapsack(n, t):
    '''
    Input: n ... the number of elements to choose from
                 n means items 1, 2, ..., n can be chosen
           t ... time limit
    Output: total value
    '''
    if n <= 0 or t <= 0:
        return 0
    elif dp_table[n, t] >= 0:
        return dp_table[n, t]
    elif time[n] > t:
        ans =  knapsack(n-1, t)
    else:
        ans = max(knapsack(n-1, t), value[n] + knapsack(n-1, t - time[n]))

    dp_table[n, t] = ans
    return ans

def all_you_can_eat(n, t):
    if n <= 0 or t <= 0:
        return 0
    else:
        # Eat the most delicious food at the beginning
        tmp1 = value[n] + all_you_can_eat(n - 1, t - time[n])
        # Eat the most delicious food at the end
        tmp2 = value[n] + knapsack(n - 1, t - 1)
        return max(tmp1, tmp2)

print(all_you_can_eat(N, T))

Submission status: Runtime Error

Solution code:
import numpy as np
N,T = map(int, raw_input().split())
L = [map(int, raw_input().split()) for i in range(N)]
d=np.zeros(1000,int)
for a,b in sorted(L):
    t=d[a:T+a]
    np.maximum(t,d[:T]+b,t)
print(max(d))

Submission status: Runtime Error

Solution code:
def all_you_can_eat(n, t, a, b):
    dp = [[0 for _ in range(2)] for _ in range(t)]
    for x in range(n):
        for i in reversed(range(t)):
            if i + a[x] < t:
                dp[i + a[x]][0] = max(dp[i + a[x]][0], dp[i][0] + b[x])
                dp[i + a[x]][1] = max(dp[i + a[x]][1], dp[i][1] + b[x])
            dp[i][1] = max(dp[i][1], dp[i][0] + b[x])
    return dp[t-1][1]


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

    print(all_you_can_eat(n, t, a, b))


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import numpy as np

N, T = map(int, input().split())
A = np.zeros([N],dtype=np.int32)
B = np.zeros([N],dtype=np.int32)
for i in range(N):
    A[i],B[i] = map(int, input().split())

Ai = np.argsort(A)
A = A[Ai]
B = B[Ai]

DP = np.full([N,T],-1)

def rec_dp(i, lim):
    global N, DP, A, B
    if DP[i][lim] != -1 :
        return DP[i][lim]
    if i==N-1:
        res = 0
    elif lim < A[i]:
        res = rec_dp(i+1, lim)
    else:
        res = max(rec_dp(i+1, lim-A[i])+B[i], rec_dp(i+1, lim))
    
    DP[i][lim] = res
    return res

mi = np.argmax(B)
Bm = B[mi]
A = np.delete(A,mi)
B = np.delete(B,mi)
    
ans = rec_dp(0,T-1) + Bm

print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

N, T = map(int, input().split())
A = np.zeros([N],dtype=np.int32)
B = np.zeros([N],dtype=np.int32)
for i in range(N):
    A[i],B[i] = map(int, input().split())

DP = np.full([N,T],-1)

def rec_dp(i, lim):
    global N, DP
    if DP[i][lim] != -1 :
        return DP[i][lim]
    if i==N-1:
        res = 0
    elif lim < A[i]:
        res = rec_dp(i+1, lim)
    else:
        res = max(rec_dp(i+1, lim-A[i])+B[i], rec_dp(i+1, lim))
    
    DP[i][lim] = res
    return res

mi = np.argmax(B)
Bm = B[mi]
A = np.delete(A,mi)
B = np.delete(B,mi)

ans = rec_dp(0,T-1) + Bm

print(int(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

N,T=map(int, input().split())
val=[list(map(int, input().split())) for i in range(N)]

#import sys
#input = sys.stdin.readline
#val = list(input()) #abc
#val=np.array(val)
#index=np.argsort(val[:,0])
#A=val[index,0].tolist()
#B=val[index,1].tolist()
val.sort()
A=[v[0] for v in val]
B=[v[1] for v in val]

#temp=np.zeros((T+1,N))
#Ts=T*np.ones(N-1)
#jun=np.arange(1,N)
#for itemp in range(T):
#    i=itemp
#    if i>=A[0]:
#        temp[i,0]=B[0]
#    if i>0:
#        temp[i,:]=np.amax([temp[i,:],temp[i-1,:]],0)
#    for jtemp in range(N-1):
#        j=jtemp+1
#        temp[i,j]=max(temp[i,j],temp[i,j-1])
#    jnext=np.amin([Ts,i+A[1:]],0)
#    jnext=[int(s) for s in jnext]
#    temp[jnext,jun]=np.amax([temp[i,:-1]+B[1:],temp[jnext,jun]],0)

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

for itemp in range(T):
    i=itemp
    if i>=A[0]:
        temp[i][0]=B[0]
    for jtemp in range(N-1):
        j=jtemp+1
        jbfo=temp[i][j-1]
        ijnow=temp[i][j]
        
        if i>0:
            temp[i][j]=max(ijnow,temp[i-1][j])
            
        temp[i][j]=max(ijnow,jbfo)
        if A[j]<T-i:
            temp[i+A[j]][j]=max(jbfo+B[j],temp[i+A[j]][j])
        else:
            temp[T][j]=max(jbfo+B[j],temp[T][j])
print(int(max(temp[-1][:])))

Submission status: Runtime Error

Solution code:
import numpy as np
n,t=map(int,input().split())
ab=[]
x=[]
a=0
for i in range(n):
    ab.append(list(map(int,input().split())))
    a += ab[i][0]
    x.append(ab[i][1])
dp = np.zeros((n,max(a,t)))
def solveDP(i,j):
    ans=0
    if i>=n: return 0
    else:
        if dp[i][j]>0:
            return dp[i][j]
        elif 0>=j:
            return solveDP(i+1,j)
        else:
            dp[i][j] = max(solveDP(i+1,j-ab[i][0])+ab[i][1],solveDP(i+1,j))
            return dp[i][j]
ans = solveDP(0,t-1)
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n,t=map(int,input().split())
ab=[]
x=[]
a=0
for i in range(n):
    ab.append(list(map(int,input().split())))
    a += ab[i][0]
    x.append(ab[i][1])
dp = np.zeros((n,max(a,t)))
def solveDP(i,j):
    ans=0
    if i>=n: return 0
    else:
        if dp[i][j]>0:
            return dp[i][j]
        elif 0>j:
            return solveDP(i+1,j)
        else:
            dp[i][j] = max(solveDP(i+1,j-ab[i][0])+ab[i][1],solveDP(i+1,j))
            return dp[i][j]
ans = solveDP(0,t-1)
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n,t=map(int,input().split())
ab=[]
x=[]
a=0
for i in range(n):
    ab.append(list(map(int,input().split())))
    a += ab[i][0]
    x.append(ab[i][1])
dp = np.zeros((n,max(a,t)))
def solveDP(i,j):
    ans=0
    if i>=n: return 0
    else:
        if dp[i][j]>0:
            return dp[i][j]
        elif 0>j:
            return solveDP(i+1,j)
        else:
            dp[i][j] = max(solveDP(i+1,j-ab[i][0])+ab[i][1],solveDP(i+1,j))
            return dp[i][j]
ans = solveDP(0,t)
print(int(ans))

Submission status: Runtime Error

Solution code:

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

def main(N,T,menu):
    #時間tを初期化
    t = 0
    #注文数の初期化
    i = 0
    sum = 0
    while t <= T:
        #時間の経過
        t += menu[i][0]
        #注文数のカウント増加
        sum += menu[i][1]
        i += 1
        if i > N:
            break
    return sum

print(main(N,T,menu))

Submission status: Runtime Error

Solution code:

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

def main(N,T,menu):
    #時間tを初期化
    t = 0
    #注文数の初期化
    i = 0
    sum = 0
    while t <= T:
        #時間の経過
        t += menu[i][0]
        #注文数のカウント増加
        sum += menu[i][1]
        i += 1
    return sum

print(main(N,T,menu))

Submission status: Runtime Error

Solution code:
N,T = map(int,input().split())
menu =[list(map(int,input().split())) for _ in range(N)]
print(menu)
def main(N,T,menu):
    #時間tを初期化
    t = 0
    #注文数の初期化
    i = 0
    sum = 0
    while t <= T:
        #時間の経過
        t += menu[i][0]
        #注文数のカウント増加
        sum += menu[i][1]
        i += 1        
    return sum

print(main(N,T,menu))

Submission status: Runtime Error

Solution code:
N,T = map(int,input().split())
menu =[list(map(int,input().split())) for _ in range(N)]
print(menu)
def main(N,T,menu):
    #時間tを初期化
    t = 0
    #注文数の初期化
    i = 0
    sum = 0
    while t <= T:
        #時間の経過
        t += menu[i][0]
        #注文数のカウント増加
        sum += menu[i][1]
        i += 1
        
    return sum

print(main(N,T,menu))

Submission status: Runtime Error

Solution code:

N,T = map(int,input().split())
menu =[list(map(int,input().split())) for _ in range(N)]
print(menu)
def main(N,T,menu):
    #時間tを初期化
    t = 0
    #注文数の初期化
    i = 0
    sum = 0
    while t <= T:
        #時間の経過
        t += menu[i][0]
        #注文数のカウント増加
        sum += menu[i][1]
        i += 1
        
    return sum

print(main(N,T,menu))

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np


N, T = map(int, input().split())
a = []
b = []
for _ in range(N):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)
a = np.array(a)
b = np.array(b)
    
costs = a[np.argsort(-a)]
cost_cumsum = np.cumsum(costs)
costs_value_sort = a[np.argsort(-b)]

values = b[np.argsort(-b)]
values_cost_sort = b[np.argsort(-a)]

# 下限の計算
index = np.sum(np.cumsum(costs) < T) - 1
if len(costs) == index + 1:
    inf = np.cumsum(values)
else:
    inf = np.cumsum(values_cost_sort)[index+1]
    
candidate = []
_range = [i for i in range(N)]

for i in range(0, N):
    if cost_cumsum[i] > T - 1:
        continue
    else:
        break

if N - i == 1:
    print(values.sum())
    
else:
    for j in range(1, N - i):
        for k in itertools.combinations(_range, j):
            k = np.array(k)
            current_cost = costs_value_sort[k].sum()
            if current_cost < T:
                for l in range(N):
                    if l not in k:
                        break
                    else:
                        continue
                ret = values[k].sum() + values[l]
            elif current_cost == T:
                ret = values[k].sum()
            else:
                continue
                
            if inf < ret:
                inf = ret
    print(inf)

Submission status: Runtime Error

Solution code:
n, t = map(int, input().split())
 
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
 
a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)
 
dp = [[0 for _ in range(t)] for _ in range(n+1)]
 
for i in range(n):
    for j in range(t):
        if j + a[i] <= t-1:
            if dp[i+1][j + a[i]] < dp[i][j] + b[i]:
                dp[i+1][j + a[i]] = dp[i][j] + b[i]
        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j]
 
ans = 0
for i in range(N):
    ans = max(ans,dp[i][t-1]+b[i])
    
print(ans)

Submission status: Runtime Error

Solution code:
#ABC145 E
N,T = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort()

a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)
    
dp = [[0 for j in range(T)] for _ in range(N+1)]
# i番目より前まで注文してT分以内(max T-1)で完食する
    
for i in range(N):
    for t in range(T): 
        if j + a[i] <= t-1:
            if dp[i+1][j + a[i]] < dp[i][j] + b[i]:
                dp[i+1][j + a[i]] = dp[i][j] + b[i]
        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j]

#一番遅いものをラスト(T-1分)に注文
#i番目をラストに注文 = dp[i][t-1] + b[i]
ans = 0
for i in range(N):
    ans = max(ans,dp[i][t-1]+b[i])
    
print(ans)

Submission status: Runtime Error

Solution code:
#ABC145 E
N,T = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort()

for ai, bi in ab:
    a.append(ai)
    b.append(bi)
    
dp = [[0]*T for _ in range(N+1)]
# i番目より前まで注文してT分以内(max T-1)で完食する
def chmax(a,b):
    if a < b:
        return b
    else:
        return a 
    
for i in range(N):
    for t in range(T): #T-1分がmax
        if t+a[i] <= T-1:
        	dp[i+1][t+a[i]] =chmax(dp[i+1][t+a[i]],dp[i][t]+b[i])
        
        dp[i+1][t] = chmax(dp[i+1][t],dp[i][t])

#一番遅いものをラスト(T-1分)に注文
#i番目をラストに注文 = dp[i][t-1] + b[i]
ans = 0
for i in range(N):
    ans = chmax(ans,dp[i][t-1]+b[i])
    
print(ans)

Submission status: Runtime Error

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