Problem:


Score : 100 points

Problem Statement

There are N items, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.

Taro has decided to choose some of the N items and carry them home in a knapsack.
The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.

Find the maximum possible sum of the values of items that Taro takes home.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq W \leq 10^5

1 \leq w_i \leq W

1 \leq v_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N W
w_1 v_1
w_2 v_2
:
w_N v_N

Output

Print the maximum possible sum of the values of items that Taro takes home.

Sample Input 1

3 8
3 30
4 50
5 60

Sample Output 1

90

Items 1 and 3 should be taken.
Then, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.

Sample Input 2

5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

Sample Output 2

5000000000

The answer may not fit into a 32-bit integer type.

Sample Input 3

6 15
6 5
5 6
6 4
6 6
3 5
7 2

Sample Output 3

17

Items 2, 4 and 5 should be taken.
Then, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.



Sample input:
3 8
3 30
4 50
5 60


Sample output:
90

Submission status: Accepted

Solution code:
import subprocess
import gzip, base64, os
import stat

gz = b'H4sIAAt5g10C/+19C3hTVbbwSZ/h1RREpyJKwABFpDS0QAuiLSVwAikgLcioeEjTlEbzMjkpxfGBtp0xhjrMjNfxzu/M5c7rOnPn4cx4HV+DlFcBlZeKPBQQRU+oSBGBokL+tfbeJz3nJAdhvP/9v/t9Bpp91jpr7/XYa6/9OtnnIZtjZobBwMmfDO5mDqFbh1YQuILhnwonSQBXxvWB72HcUC4H4GwFXQVXoUp7WNFyamR0mfCXBX9lGRQuy6hQpUMZnZwaFGk2p/xUqNLBbk6Vcpw5mQ9l3euj2L2+parUnEXxxbnqfBksXw/L18Po5ZTL4FSprF8W+6tl+Fqml5zOYHQzFPT4mX9UrMfrp+5idr+rQpW2MrpWTb5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nk4bY4AldtCWCut4UR0Dh0osmaOMBcQhrsYDaQFmBFTYdh0D3LnfLgbl0eaNTtDWljSAlCsF1wkcvZyv4IqtRbwrPWnuKK2kdA9STgyWzM/DTUaFGLHWBn6Wiy5M+pdVIqA8HhEbohMF4+EBVwJu2zWEgZKMrGsIC1A3lIJXGGyFqgW69rotOCyG+WLDBEHD+nJoSwasNaT63zxdoSvEWtFJvzWi1wxB38ZZcFw4rPCIwscEbCTem1i32w8XY7puddZ4mKzbdsAcbJmTHqAe6NgTA5pCjcrpdsBaVaJoSTjnSRhGMbmB7QaGDtpBe/fRKwXakV4IQBNVhXC/c417BIl/aOJXazsHkLl9QbXFXmnBMhaS1CfqmrfCJLq/bCVMwEYYzdrAJ/IkgiSYcuAMNWhdD9UjdqbUiXT9pl5fR45LJhUbJBvIb+hS3Unfl4J86BafrxScre3Firya9EACOVCO4fUFxBcSsILAKhJzL3LZ0dVwHMc0PvYDoatSYgjz5B11+c7MQdIfCAYgmHiiwqTjVlS6zv4CIgn5Camwe9Lm+QL07TWeZRjvW66UEv4X+5RggF7jDER8WVVUF+GIq3CRyHIU7TYcDVp3MmnCaAVFJMCLaXGmEAF+rFsDv7oEoBvOINO4dXNFb89ZS9SgxtdfGcQVHY93/BTZN753znAAA'
bin = gzip.decompress(base64.b64decode(gz))
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
with open(pymain, "wb") as f:
    f.write(bin)
os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if p == "":
    pymain = "./" + pymain
subprocess.call(pymain)


# compiled by pythran
'''
                                        #pythran export main2()
import numpy as np
i8 = np.int64
i4 = np.int32


def solve(w, v, W):
    dp = np.zeros((w.shape[0], W + 1), i8)
    dp[0, w[0]] = v[0]
    for n in range(1, w.shape[0]):
        dp[n, :w[n]] = dp[n - 1, :w[n]]
        dp[n, w[n]] = max(v[n], dp[n - 1, w[n]])
        for j in range(w[n] + 1, W + 1):
            if dp[n - 1, j - w[n]] > 0:
                dp[n, j] = max(dp[n - 1, j - w[n]] + v[n], dp[n - 1, j])
            else:
                dp[n, j] = dp[n - 1, j]
    return dp[w.shape[0] - 1].max()


def main2():
    stdin = open('/dev/stdin')
    N, W = map(int, stdin.readline().split())
    w = np.empty(N, i8)
    v = np.empty(N, i8)
    for n in range(N):
        w[n], v[n] = map(int, stdin.readline().split())
    ans = solve(w, v, W)
    print(ans)
'''

Submission status: Accepted

Solution code:
n, w = map(int, input().split())
e = tuple(map(int, input().split()) for _ in range(n))
wt, vt = zip(*e)

dp = tuple([0] * (w + 1) for _ in range(n + 1))

for i in range(n):
    dp[i + 1][:wt[i]] = dp[i][:wt[i]]
    for j in range(wt[i], w + 1):
        dp[i + 1][j] = max(dp[i][j], dp[i][j - wt[i]] + vt[i])
print(dp[n][w])

Submission status: Accepted

Solution code:
N, W = map(int, input().split())
dp = [0]*(W+1)
for i in range(N):
  w, v = map(int, input().split())
  for j in range(W, w-1, -1):
    dp[j] = max(dp[j], dp[j-w]+v)
print(dp[W])

Submission status: Accepted

Solution code:
N, W = map(int, input().split())

dp = [0] * (W+1)
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W, w-1, -1):
        a = dp[j-w]+v
        if dp[j] < a:
            dp[j] = a

print(dp[W])

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

N, W = na()
dp = [[0] * (W+1) for i in range(N+1)]  # dp[j][w] w以下でj番目までの品物で最大の価値
for i in range(1, N+1):
    wi, vi = na()
    for w in range(1, W+1):
        if w - wi >= 0:
            dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - wi] + vi)
        else:
            dp[i][w] = dp[i - 1][w]
print(dp[N][w])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


n,w = map(int,input().split())
W = [0 for i in range(n)];V = [0 for i in range(n)]
for i in range(n):
    W[i],V[i] = map(int,input().split())
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j >= W[i]:
            dp[i+1][j] = max(dp[i][j],dp[i][j-W[i]]+V[i])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][w])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


n,w = map(int,input().split())
WV = [list(map(int,input().split())) for i in range(n)]
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j >= WV[i][0]:
            dp[i+1][j] = max(dp[i][j],dp[i][j-WV[i][0]]+WV[i][1])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][w])

Submission status: Accepted

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

dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(1, w+1):
        #print(dp)
        if j - goods[i-1][0] >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-goods[i-1][0]] + goods[i-1][1])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[n][w])

Submission status: Accepted

Solution code:
n,w_max = map(int,input().split())
w = [0]
v = [0]
for _ in range(n):
    W,V = map(int,input().split())
    w.append(W)
    v.append(V)

dp = [[0]*(w_max+1) for i in range(n+1)]
for i in range(1,n+1):
    for u in range(w_max+1):
        if u>=w[i]:
            dp[i][u] = max(dp[i-1][u-w[i]]+v[i],dp[i-1][u])
        else:###
            dp[i][u] = dp[i-1][u]


print(dp[n][w_max])

Submission status: Accepted

Solution code:
#D

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

wlist = []
vlist = []
for i in range(n):
    wk,vk=map(int,input().split())
    wlist.append(wk)
    vlist.append(vk)

dp=[]
for i in range(n+1):
    dp.append([0]*(w+1))


for i in range(1,n+1):
    #このループの中で、wlist[i-1],vlist[i-1]の品物を入れるか判断する
    for j in range(w+1):
        #このループの中で,dp[i][j]の更新を考える
        if j-wlist[i-1] >=0:
            #dp[i-1][j] と dp[i-1][j]+vlist[i-1]のうち大きい方
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-wlist[i-1]]+vlist[i-1])
        else:
            dp[i][j] = dp[i-1][j]
#        print(dp)
print(dp[n][w])

Submission status: Accepted

Solution code:
import numpy as np

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

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

val = np.zeros(W+1,dtype = int)

for i in range(N):
  item_weight = item[i][0]
  val[item_weight :] = np.maximum(val[item_weight :], val[:-item_weight] + item[i][1])
  
print(max(val))

Submission status: Accepted

Solution code:
n, w = [int(x) for x in input().split()]
W = []
V = []
for i in range(n):
  wi, vi = [int(x) for x in input().split()]
  W.append(wi)
  V.append(vi)

dp = []
for i in range(n+1):
  dp.append([0]*(w+1))

for i in range(n):
  for sum_w in range(w + 1):
    # 選ぶ場合
    if sum_w - W[i] >= 0:
      dp[i+1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - W[i]] + V[i])

    # 選ばない場合
    dp[i+1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

print(dp[n][w])

Submission status: Accepted

Solution code:
N, W = map(int, input().split())

weights = [None for i in range(N)]
values = [None for i in range(N)]

# dp[i][j] = maximum value using at most i weight and using elements 1,...,j

dp = [[0 for i in range(N+1)] for j in range(W+1)]

for i in range(N):
    w, v = map(int, input().split())
    weights[i] = w
    values[i] = v
    
for weight in range(W+1):
    for item in range(1,N+1):

        # Case: dont include item
        dp[weight][item] = max(dp[weight][item],
                               dp[weight][item-1])

        # Case: include item
        dp[weight][item] = max(dp[weight][item],
                               dp[weight-1][item])
        
        if weights[item-1] > weight: continue
 
        # Case: include item
        dp[weight][item] = max(dp[weight][item],
                               values[item-1] + dp[weight - weights[item-1]][item - 1])
    
print(max(dp[-1]))

Submission status: Accepted

Solution code:
import numpy as np

n, W = map(int, input().split())
wv = np.array([list(map(int, input().split())) for i in range(n)])

dp = np.zeros((n + 1, W + 1), dtype=np.int)


def chmax(a, b):
    if a > b:
        return a
    else:
        return b


# # 遅い
# for i in range(n):
#     for sum_w in range(W + 1):
#         if sum_w >= wv[i, 0]:
#             dp[i + 1][sum_w] = chmax(dp[i + 1][sum_w], dp[i][sum_w - wv[i, 0]] + wv[i, 1])
#         dp[i + 1][sum_w] = chmax(dp[i + 1][sum_w], dp[i][sum_w])

for i in range(0, n):
    w, v = wv[i, :]
    dp[i + 1, w:] = np.maximum(dp[i, w:], dp[i, :-w] + v)
    dp[i + 1, :] = np.maximum(dp[i + 1, :], dp[i, :])

print(int(dp[n , W]))

Submission status: Accepted

Solution code:
N,W=map(int,input().split())
w,v=[],[]
for i in range(N):
    weight, value = map(int,input().split())
    w.append(weight)
    v.append(value)
dp = [[0 for _ in range(100100)] for _ in range(N+2)]
for i in range(N):
    for sum_w in range(W+1):
        if sum_w -w[i] >=0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w-w[i]] + v[i])
        dp[i+1][sum_w]=max(dp[i+1][sum_w],dp[i][sum_w])
print(dp[N][W])

Submission status: Accepted

Solution code:


N, W=[int(i) for i in input().split()]
wv=[[int(i) for i in input().split()] for _ in range(N)]


dp=[[0]*(W+1) for _ in range(N)]

for i in range(N):
    for w in range(W+1):
        if i==0:
            if wv[i][0]<=w:
                dp[i][w]=wv[i][1]
        else:
            if w>=wv[i][0]:
                dp[i][w]=max(dp[i-1][w-wv[i][0]]+wv[i][1],dp[i-1][w])
            else:
                dp[i][w]=dp[i-1][w]

print(max(dp[-1]))

Submission status: Accepted

Solution code:
n,w=map(int,input().split())
weight,value=[0]*110,[0]*110
dp = [[0 for _ in range(100100)] for _ in range(110)]
for i in range(n):
    weight[i],value[i] = map(int,input().split())
for i in range(n):
    for  sum_w in range(w+1):
        #i番目の品物を選ぶ
        if(sum_w - weight[i] >=0):
            dp[i+1][sum_w] =max(dp[i+1][sum_w], dp[i][sum_w - weight[i]]+ value[i])
        #選ばない場合
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print(dp[n][w])

Submission status: Accepted

Solution code:
def ks(n, W, arr):
    dp = [[0 for i in range(W+1)] for j in range(n+1)]
    for i in range(1,n+1):
        for j in range(1,W+1):
            if arr[i-1][0] > j:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-arr[i-1][0]]+arr[i-1][1])
    return dp[n][W]

if __name__ == "__main__":
    n, W = map(int, input().split())
    arr = []
    for i in range(n):
        w,v = map(int, input().split())
        arr.append([w,v])
    arr.sort(key = lambda x:x[0])
    ans = ks(n,W,arr)
    print(ans)

Submission status: Accepted

Solution code:
n,w=map(int,input().split())
weight,value=[0]*110,[0]*110
dp = [[0 for _ in range(100100)] for _ in range(110)]
for i in range(n):
    weight[i],value[i] = map(int,input().split())
for i in range(n):
    sum_w =0
    while sum_w <= w:
        #i番目の品物を選ぶ
        if(sum_w - weight[i] >=0):
            dp[i+1][sum_w] =max(dp[i+1][sum_w], dp[i][sum_w - weight[i]]+ value[i])
        #選ばない場合
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
        sum_w +=1
print(dp[n][w])

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for i in range(N)]

    dp = np.zeros((N+1, W+1), dtype=int)

    for i in range(N):
        w, v = wv[i]
        dp[i+1] = dp[i]
        dp[i+1, w:] = np.maximum(dp[i+1, w:], dp[i+1, :-w] + v)
    
    print(dp[-1][-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, W = map(int, input().split())
mX = [tuple(map(int, input().split()))
      for _ in range(N)]

# dp[i][w] := max v
dp = [[0,] * (W+1),]

for w,v in mX:
    nDp = [max(dp[-1][t], dp[-1][t-w]+v)
           if t-w >= 0 else dp[-1][t]
           for t in range(W+1)]
    dp.append(nDp)

print(dp[-1][-1])