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^9

1 \leq w_i \leq W

1 \leq v_i \leq 10^3

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

1 1000000000
1000000000 10

Sample Output 2

10

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: Wrong Answer

Solution code:
#input
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

#output
import numpy as np
V = max(v)
INF = 10**6
dp = np.zeros((N+1, N*V+1), int)
dp[0] = INF
dp[0, 0] = 0

for i in range(N):
    dp[i+1, v[i]:] = np.minimum(dp[i, v[i]:], dp[i, :-v[i]]+w[i])
    dp[i+1, :v[i]] = dp[i, :v[i]]
        
answer = 0
for i in range(N*V+1):
    if dp[N, i] <= W:
        answer = i

print(answer)

Submission status: Wrong Answer

Solution code:
#input
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

#output
import numpy as np
V = max(v)
INF = 10**8
dp = np.zeros((N+1, N*V+1), int)
dp[0] = INF
dp[0, 0] = 0

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

answer = 0
for i in range(N*V+1):
    if dp[N, i] <= W:
        answer = i

print(answer)

Submission status: Wrong Answer

Solution code:
#input
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

#output
import numpy as np
V = max(v)
INF = 10**6
dp = np.zeros((N+1, N*V+1), int)
dp[0] = INF
dp[0, 0] = 0

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

answer = 0
for i in range(N*V+1):
    if dp[N, i] <= W:
        answer = i

print(answer)

Submission status: Wrong Answer

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

dp=[float("inf")]*(10**4+1)
dp[0]=0
for i in range(n):
  for j in range(10**4,A[i][1]-1,-1):
    dp[j]=min(dp[j],dp[j-A[i][1]]+A[i][0])
ans=0
for v,e in enumerate(dp):
  if e<=w:
    ans=v
print(ans)

Submission status: Wrong Answer

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

dp=[float("inf")]*(10**3+1)
dp[0]=0
for i in range(n):
  for j in range(10**3,A[i][1]-1,-1):
    dp[j]=min(dp[j],dp[j-A[i][1]]+A[i][0])
ans=0
for v,e in enumerate(dp):
  if e<=w:
    ans=v
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

N, W = MAP()
w, v = ZIP(N)
max_v = N*sum(v)
dp = [INF]*(max_v+1)
dp[0] = 0
for i in range(N):
	for j in range(max_v-v[i], -1, -1):
		if j-v[i] >= 0:
			dp[j] = min(dp[j], dp[j-v[i]]+w[i])

ans = 0
for i in range(max_v+1):
	if dp[i] <= W:
		ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
n, w = map(int, input().split())
dp = [[(10**9+1) for _ in range(10**5)] for _ in range(n)]
wn, vn = map(int, input().split())
dp[0][0] = 0
dp[0][vn] = wn
for i in range(1, n):
    wn, vn = map(int, input().split())
    for j in range(10**5):
        if (j - vn) >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-vn] + wn)
        else:
            dp[i][j] = dp[i-1][j]
#print(dp)
ansl = dp[n-1][::-1]
#print(ansl)
for k in range(len(ansl)):
    if ansl[k] <= w:
        print(10**5-1-k)
        break

Submission status: Wrong Answer

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

dp = [[float('inf')] * (10**5 + 100) for _ in range(110)]
dp[0][0] = 0

for i in range(N):
    for sum_v in range(10**5 + 100):
        if sum_v - T[i][1] >= 0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i]
                                 [sum_v - T[i][1]] + T[i][0])
        else:
            dp[i+1][sum_v] = dp[i][sum_v]

ans = 0
for sum_v in range(10**5 + 100):
    if dp[N][sum_v] <= W:
        ans = sum_v

print(ans)

Submission status: Wrong Answer

Solution code:


def submit():
    n, w = map(int, input().split())
    val_max = 1000
    # dp[i][j] = item iまでで価値jになるようにした時の最小重み
    dp = [[float('inf') for _ in range(val_max + 1)] for _ in range(n + 1)]
    for i in range(n + 1):
        dp[i][0] = 0

    for i in range(1, n + 1):
        wi, vi = map(int, input().split())
        for j in range(val_max + 1):
            if 0 <= j - vi <= val_max:
                dp[i][j] = min(dp[i - 1][j],
                               dp[i - 1][j - vi] + wi)
            else:
                dp[i][j] = dp[i - 1][j]

    ans = 0
    for i in range(val_max + 1):
        if dp[n][i] <= w:
            ans = i
    print(ans)

submit()

Submission status: Wrong Answer

Solution code:
import numpy as np
N,W=map(int,input().split())
dp=np.full(10**5,W+1)
dp[0]=0
for i in range(N):
    w,v=map(int,input().split())
    dp[v:]=np.minimum(dp[:-v]+w,dp[v:])
print(np.max(np.where(dp<=W)))

Submission status: Wrong Answer

Solution code:
N, W = [int(i) for i in input().split()]
weight, value = [0] * (N + 1), [0] * (N + 1)
for i in range(1, N + 1):
    weight[i], value[i] = [int(i) for i in input().split()]

sum_value = sum(value)
dp = [[0] * (sum_value + 1) for _ in range(N + 1)]
 
for i in range(1, N + 1):
    for j in range(sum_value + 1):
        #
        if j >= value[i]:
            dp[i][j] = weight[i] + dp[i- 1][j - value[i]]
        dp[i][j] = min(dp[i - 1][j], dp[i][j])
 
ans = 0
for i in range(sum_value + 1):
    if dp[N][i] == W:
        ans = i
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N, W = [int(i) for i in input().split()]
weight, value = [0] * (N), [0] * (N)
for i in range(N):
    weight[i], value[i] = [int(i) for i in input().split()]

#%%

sum_value = sum(value)
dp = [[float("inf")] * (sum_value + 1) for _ in range(N + 1)]
dp[0][0] = 0

#%%

for i in range(N):
    for j in range(sum_value + 1):
        if j >= value[i]:
            dp[i + 1][j] = min(weight[i] + dp[i][j - value[i]], dp[i + 1][j])
        else:
          dp[i + 1][j] =  dp[i][j]

#%%

ans = 0
for i in range(sum_value + 1):
    if dp[N][i] <= W:
        ans = i
        
print(ans)

Submission status: Wrong Answer

Solution code:
N, W = [int(i) for i in input().split()]
weight, value = [0] * (N), [0] * (N)
for i in range(N):
    weight[i], value[i] = [int(i) for i in input().split()]

#%%

sum_value = sum(value)
dp = [[float("inf")] * (sum_value + 1) for _ in range(N + 1)]
dp[0][0] = 0

#%%

for i in range(N):
    for j in range(sum_value + 1):
        if j >= value[i]:
            dp[i + 1][j] = min(weight[i] + dp[i][j - value[i]], dp[i + 1][j])
        else:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

#%%

ans = 0
for i in range(sum_value + 1):
    if dp[N][i] <= W:
        ans = i
        
print(ans)

Submission status: Wrong Answer

Solution code:

N, W = [int(i) for i in input().split()]
weight, value = [0] * (N + 1), [0] * (N + 1)
for i in range(1, N + 1):
    weight[i], value[i] = [int(i) for i in input().split()]
#%%
sum_value = sum(value)
dp = [[0] * (sum_value + 1) for _ in range(N + 1)]

#%%
for i in range(1, N + 1):
    for j in range(1, sum_value + 1):
        #
        if j >= value[i]:
            dp[i][j] = weight[i] + dp[i- 1][j - value[i]]
        else:
            dp[i][j] = dp[i - 1][j]

#%%
ans = 0
for i in range(sum_value + 1):
    if dp[N][i] == W:
        ans = i
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, W = list(map(int, input().split()))
INF = int(1e11)
dp = [[INF for i in range(int(1e5)+1)] for j in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
    w, v = list(map(int, input().split()))
    for j in range(0, int(1e5)+1):
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for i in range(N+1):
    for j in reversed(range(int(1e5)+1)):
        if dp[i][j] <= W:
            print(j)
            break

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def iinput():
    return int(input())


def tinput():
    return input().split()


def rinput():
    return map(int, tinput())


def rlinput():
    return list(rinput())


mod = int(1e9)+7


def factors(n):
    return set(reduce(list.__add__,
                      ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))


# ----------------------------------------------------

if __name__ == "__main__":
    n, weigh = rinput()
    w, v = [], []
    for i in range(n):
        wi, vi = rinput()
        w.append(wi)
        v.append(vi)

    mxv = int(1e3)+1
    dp = [[float('inf') for i in range(mxv+1)]for j in range(n+1)]
    for i in range(n+1):
        dp[i][0]=0
    # print(w_v)
    for item in range(1, n+1):
        for val in range(1, mxv+1):
            if v[item-1] <= val:
                dp[item][val] = min(
                    dp[item-1][val-v[item-1]]+w[item-1], dp[item-1][val])
            else:
                dp[item][val] = dp[item-1][val]
    # print(dp)
    ans=float('inf')
    for i in range(mxv,0,-1):
        if dp[n][i]<=weigh:
            ans=i
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
w, v = [0]*N, [0]*N
total_v = 0
for i in range(N):
  w[i], v[i] = map(int, input().split())
  total_v += v[i]

dp = [[float('inf') for _ in range(total_v+1)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
  for j in range(1, total_v+1):
    if j < v[i-1]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1])
for i in range(total_v, -1, -1):
  if dp[-1][i] <= W:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(N)]
inf = 10**9+7

"""
dp[n][v]: 1~n番目までの品物から、総価値v以上になるように選んだ時の総重量の最小値
"""
dp = [[inf] * (10**5+1) for _ in range(N+1)]
dp[0][0] = 0

sum_values = 0
for n in range(1, N+1):
    sum_values += items[n-1][1]
    for v in range(sum_values+1):
        if v >= items[n-1][1]:
            dp[n][v] = min(dp[n-1][v], dp[n-1][v-items[n-1][1]] + items[n-1][0])
        else:
            dp[n][v] = dp[n-1][v]

result = 0
for v in range(1, 10**5):
    if dp[N][v] <= W:
        result = v
    elif dp[N][v] == inf:
        continue
    else:
        break
print(result)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(N)]
inf = 10**9+7

"""
dp[n][v]: 1~n番目までの品物から、総価値v以上になるように選んだ時の総重量の最小値
"""
dp = [[inf] * (10**5+1) for _ in range(N+1)]
dp[0][0] = 0

sum_values = 0
for n in range(1, N+1)[:3]:
    sum_values += items[n-1][1]
    for v in range(sum_values+1):
        if v >= items[n-1][1]:
            dp[n][v] = min(dp[n-1][v], dp[n-1][v-items[n-1][1]] + items[n-1][0])
        else:
            dp[n][v] = dp[n-1][v]

result = 0
for v in range(1, 10**5+1):
    if dp[N][v] <= W:
        result = v
    elif dp[N][v] == inf:
        continue
    else:
        break


print(result)

Submission status: Wrong Answer

Solution code:
import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
'''
w = [0]*N
v = [0]*N
for i in range(N):
        w[i], v[i] = map(int, sys.stdin.readline().split())
'''
INF = 10**11+1
dp = [[INF]*(N+1) for j in range(N*(10**3)+10)]
i = 0
ans = INF
while(True):
        for j in range(1, N+1):
                #print(i, j)
                w = WV[j-1][1]
                if i-w >= 0:
                        dp[i][j] = min(dp[i][j-1], dp[i-w][j-1]+WV[j-1][0])
                        #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        #print(dp[i][N])
        #print(i, dp[i][N])
        if dp[i][N] > W and ans <= W:
                print(i-1)
                exit()
        ans = dp[i][N]
        '''
        if dp[i][N] >= W:
                if ans == 0:
                        ans = dp[i][N]
                elif ans < dp[i][N]:
                        print(i)
                        exit()
                print(i, ans)
        '''
        i += 1

Submission status: Wrong Answer

Solution code:
import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
'''
w = [0]*N
v = [0]*N
for i in range(N):
        w[i], v[i] = map(int, sys.stdin.readline().split())
'''
INF = 10**11+1
dp = [[INF]*(N+1) for j in range(N*(10**3)+10)]
i = 1
ans = INF
while(True):
        for j in range(1, N+1):
                #print(i, j)
                w = WV[j-1][1]
                if i-w > 0:
                        dp[i][j] = min(dp[i][j-1], dp[i-w][j-1]+WV[j-1][0])
                        #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        #print(dp[i][N])
        print(i, dp[i][N])
        if dp[i][N] > W and ans <= W:
                print(i-1)
                exit()
        ans = dp[i][N]
        '''
        if dp[i][N] >= W:
                if ans == 0:
                        ans = dp[i][N]
                elif ans < dp[i][N]:
                        print(i)
                        exit()
                print(i, ans)
        '''
        i += 1

Submission status: Wrong Answer

Solution code:
import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
'''
w = [0]*N
v = [0]*N
for i in range(N):
        w[i], v[i] = map(int, sys.stdin.readline().split())
'''
INF = 10**11+1
dp = [[INF]*(N+1) for j in range(N*(10**3)+10)]
i = 1
ans = INF
while(True):
        for j in range(1, N+1):
                #print(i, j)
                w = WV[j-1][1]
                if i-w >= 0:
                        dp[i][j] = min(dp[i][j-1], dp[i-w][j-1]+WV[j-1][0])
                        #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        #print(dp[i][N])
        if dp[i][N] > W and ans <= W:
                print(i)
                exit()
        ans = dp[i][N]
        '''
        if dp[i][N] >= W:
                if ans == 0:
                        ans = dp[i][N]
                elif ans < dp[i][N]:
                        print(i)
                        exit()
                print(i, ans)
        '''
        i += 1

Submission status: Wrong Answer

Solution code:
import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
'''
w = [0]*N
v = [0]*N
for i in range(N):
        w[i], v[i] = map(int, sys.stdin.readline().split())
'''
INF = 10**11+1
dp = [[INF]*(N+1) for j in range(N*(10**3)+10)]
i = 1
ans = 0
while(True):
        for j in range(1, N+1):
                #print(i, j)
                w = WV[j-1][1]
                if i-w >= 0:
                        dp[i][j] = min(dp[i][j-1], dp[i-w][j-1]+WV[j-1][0])
                        #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        #print(dp[i][N])
        if dp[i][N] > W and ans <= W and ans!=0:
                print(i)
                exit()
        ans = dp[i][N]
        '''
        if dp[i][N] >= W:
                if ans == 0:
                        ans = dp[i][N]
                elif ans < dp[i][N]:
                        print(i)
                        exit()
                print(i, ans)
        '''
        i += 1

Submission status: Wrong Answer

Solution code:
import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
'''
w = [0]*N
v = [0]*N
for i in range(N):
        w[i], v[i] = map(int, sys.stdin.readline().split())
'''
INF = 10**11+1
dp = [[INF]*(N+1) for j in range(N*(10**3)+10)]
i = 1
ans = 0
while(True):
        for j in range(1, N+1):
                #print(i, j)
                w = WV[j-1][1]
                if i-w >= 0:
                        dp[i][j] = min(dp[i][j-1], dp[i-w][j-1]+WV[j-1][0])
                        #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        print(dp[i][N])
        if dp[i][N] > W and ans <= W and ans!=0:
                print(i)
                exit()
        ans = dp[i][N]
        '''
        if dp[i][N] >= W:
                if ans == 0:
                        ans = dp[i][N]
                elif ans < dp[i][N]:
                        print(i)
                        exit()
                print(i, ans)
        '''
        i += 1

Submission status: Wrong Answer

Solution code:
def solve():
    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(N)]
    max_v = 10 ** 5 + 100
    INF = 10 ** 8
    
    dp = [[INF] * max_v for i in range(N+1)]
    dp[0][0] = 0

    for i in range(N):
        for s in range(max_v):
            a, b = A[i]
            if s-b >= 0:
                dp[i+1][s] = min(dp[i+1][s], dp[i][s-b] + a)
            dp[i+1][s] = min(dp[i+1][s], dp[i][s])
    
    ans = 0
    for i in range(max_v):
        if dp[N][i] <= M:
            ans = i
    
    return ans

print(solve())

Submission status: Wrong Answer

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

INF = 100 # 10**9 + 100
MAX_V = 100 # 10**5 + 100
dp = [INF] * (MAX_V + 1)
dp[0] = 0

for wi, vi in wv:
    for sum_v in range(MAX_V, vi-1, -1):
        dp[sum_v] = min(dp[sum_v - vi] + wi, dp[sum_v])
#print(dp)
ans = 0
for i in range(MAX_V, -1, -1):
    if dp[i] <= w:
        print(i)
        exit()
#print(ans)

Submission status: Wrong Answer

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

INF = 10**9 + 100
MAX_V = 10**5 + 100
dp = [INF] * (MAX_V + 1)
dp[0] = 0

for wi, vi in wv:
    for sum_v in range(vi, MAX_V):
        dp[sum_v] = min(dp[sum_v - vi] + wi, dp[sum_v])
#print(dp)
ans = 0
for i in range(MAX_V):
    if dp[i] <= w:
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())

inf=float("inf")
sumV=sum(v)
dp=[[inf]*(sumV+1) for i in range(N+1)]
dp[0][0]=0

for i in range(sumV+1):
    for g in range(N):
        if i>=v[g]:
            dp[g+1][i]=min(w[g]+dp[g][i-v[g]],dp[g][i])
        else:
            dp[g+1][i]=dp[g][i]

ans=0
for g in range(len(dp[-1])):
    if dp[-1][g]!=inf:
        if dp[-1][g]<=W:
            ans=max(g,ans)
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

INF = 10**9
MAX_V = 10 ** 6 + 100

dp = np.full((n+1, MAX_V), INF, np.int64)
dp[0][0] = 0

for i, (wi, vi) in enumerate(wv):
    dp[i+1] = dp[i]
    np.minimum(dp[i+1][vi:], dp[i][:-vi] + wi, out=dp[i+1][vi:])

ans = np.where(dp[n] <= w)[0][-1]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

INF = 10**9
MAX_V = 10 ** 5 + 100

dp = np.full((n+1, MAX_V), INF, np.int64)
dp[0][0] = 0

for i, (wi, vi) in enumerate(wv):
    dp[i+1] = dp[i]
    np.minimum(dp[i+1][vi:], dp[i][:-vi] + wi, out=dp[i+1][vi:])

ans = np.where(dp[n] <= w)[0][-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n,w = list(map(int,input().split()))
arr = []
dp = [0 for i in range(w+1)]
for i in range(n):
	wt,val = list(map(int,input().split()))
	for j in range(w,wt,-1):
		dp[j] = max(dp[j],dp[j-wt]+val)
		# print(dp)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n,w = list(map(int,input().split()))
arr = []
dp = [0 for i in range(w+1)]
for i in range(n):
	wt,val = list(map(int,input().split()))
	for j in range(w,wt,-1):
		dp[j] = max(dp[j],dp[j-wt]+val)
		# print(dp)
print(max(dp))

Submission status: Wrong Answer

Solution code:
import numpy as np

n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

MAX_V = 10**5 + 100
INF = 10**9

dp = np.full((n+1, MAX_V), INF, dtype=np.int64)

dp[0][0] = 0
for i, (wi, vi) in enumerate(wv):
    dp[i+1] = dp[i]
    np.minimum(dp[i][vi:], dp[i][:-vi] + wi, out=dp[i+1][vi:])

#print(dp)
#print(np.where(dp[n]<=w))
ans = np.where(dp[n]<=w)[0][-1]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

MAX_V = 10**6 + 1
INF = 10**9

dp = np.full((n+1, MAX_V), INF, dtype=np.int64)

dp[0][0] = 0
for i, (wi, vi) in enumerate(wv):
    dp[i+1] = dp[i]
    np.minimum(dp[i][vi:], dp[i][:-vi] + wi, out=dp[i+1][vi:])

#print(dp)
#print(np.where(dp[n]<=w))
ans = np.where(dp[n]<=w)[0][-1]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

MAX_V = 10**3 + 1
INF = 10**9

dp = np.full((n+1, MAX_V), INF, dtype=np.int64)

dp[0][0] = 0
for i, (wi, vi) in enumerate(wv):
    dp[i+1] = dp[i]
    np.minimum(dp[i][vi:], dp[i][:-vi] + wi, out=dp[i+1][vi:])

#print(dp)
#print(np.where(dp[n]<=w))
ans = np.where(dp[n]<=w)[0][-1]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  N,W=map(int,input().split())
  Wlist=[]
  Vlist=[]
  for i in range(N):
    w,v=map(int,input().split())
    Wlist+=[w]
    Vlist+=[v]
  Vmax=max(Vlist)
  V=Vmax*N
  dp=[[float('inf') for p in range(V+1)] for i in range(N)]
  for i in range(V+1):
    if i<=Vlist[0]:
      dp[0][i]=Wlist[0]
  dp[0][0]=0
  for i in range(1,N):
    vi=Vlist[i]
    wi=Wlist[i]
    for j in range(V+1):
      if j-vi>=0:
        dp[i][j]=min(dp[i-1][j-vi]+wi,dp[i-1][j])
      else:
        dp[i][j]=min(dp[i-1][j],dp[i][j])
    print(dp[i])
  dpn=dp[N-1]
  ans=0
  for i in range(V+1):
    if dpn[i]<=W:
      ans=i
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
def main():
  N,W=map(int,input().split())
  Wlist=[]
  Vlist=[]
  for i in range(N):
    w,v=map(int,input().split())
    Wlist+=[w]
    Vlist+=[v]
  Vmax=max(Vlist)
  V=Vmax*N
  dp=[[0 for p in range(V+1)] for i in range(N)]
  for i in range(V+1):
    if i<=Vlist[0]:
      dp[0][i]=Wlist[0]
  for i in range(1,N):
    vi=Vlist[i]
    for j in range(V+1):
      if j-vi>=0:
        dp[i][j]=min(dp[i-1][j-vi]+Wlist[i],dp[i-1][j])
      else:
        dp[i][j]=min(dp[i-1][j],dp[i][j])
    print(dp)
  dpn=dp[N-1]
  ans=0
  for i in range(V+1):
    if dpn[i]<=W:
      ans=i
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n,W = map(int,input().split())
wt =[];val=[]

dp = [[0 for i in range(W+1)] for j in range(n)]
for _ in range(n):
  wi , vi= map(int,input().split())
  wt.append(wi)
  val.append(vi)

for i in range(W+1):
  if i>=wt[0]:
    dp[0][i]=val[0]   
  else:
    dp[0][i]=0
    
    
    
#print(dp)  
for i in range(1,n):
  wi = wt[i]
  vi = val[i]
  for w in range(1,W+1):
    if wi <= w:
      dp[i][w] = max(vi + dp[i-1][w-wi] , dp[i-1][w] )
    else:
      dp[i][w] = dp[i-1][w]

print(dp)

Submission status: Wrong Answer

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

MAX_V = 10 ** 3
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [10**9+7 for _ in range(MAX_V + 1)]
dp[0] = 0

for w, v in wv:
    for j in range(MAX_V, -1, -1):
        if j - v >= 0:
            dp[j] = min(dp[j],dp[j - v] + w)

mv = 0
for i in range(MAX_V + 1):
    if dp[i] <= W:
        mv = i

print(mv)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,w = get_nums_l()
ppp = list(map(lambda s: tuple(map(int,s.strip().split())), sys.stdin.readlines()))

# dp[i] = 価値iを得られる最小の重さ
dp = [9999999999999999999] * (n*1000)
dp[0] = 0

for p in ppp:
    we = p[0]
    va = p[1]
    for i in reversed(range(len(dp))):
        if i+va >= len(dp):
            continue
        ne = i+va
        dp[ne] = min(dp[ne], dp[i]+we)

# log(dp)

for i,we in reversed(list(enumerate(dp))):
    if we <= w:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [10**9+7] * (10**3+2)
dp[0] = 0

for i in range(N):
    w, v = wv[i]
    for j in range(10**3+1):
        if j >= v:
            dp[j] = min(dp[j], dp[j-v]+w)

ret = 0
for i in range(1, 10**3+1):
    if dp[i] <= W:
        ret = i

print(ret)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [10**9+7] * (10**3+2)
dp[0] = 0

for i in range(1, N+1):
    w, v = wv[i-1]
    for j in range(10**3, 0, -1):
        if j-v >= 0:
            dp[j] = min(dp[j], dp[j-v]+w)

ret = 0
for i in range(1, 10**3+1):
    if dp[i] <= W:
        ret = i
print(ret)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [10**9+7] * (10**3+2)
dp[0] = 0

for i in range(1, N+1):
    w, v = wv[i-1]
    for j in range(10**3, 0, -1):
        t = [dp[j], dp[j+1]]
        if j-v >= 0:
            t.append(dp[j-v]+w)
        dp[j] = min(t)

ret = 0
for i in range(1, 10**3+1):
    if dp[i] <= W:
        ret = i
print(ret)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[10**9+7] * (10**3+2) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

# dp[i-1][j] 今回の品物を選ばない場合
# dp[i-1][j-v]+w 今回の品物も選ぶ場合

for i in range(1, N+1):
    w, v = wv[i-1]
    for j in range(10**3, 0, -1):
        t = [dp[i-1][j]]
        if j-v >= 0:
            t.append(dp[i-1][j-v]+w)
        dp[i][j] = min(t)

ret = 0
for i in range(1, 10**3+1):
    if dp[-1][i] <= W:
        ret = i
print(ret)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[10**9+7] * (10**3+2) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

# dp[i-1][j] 今回の品物を選ばない場合
# dp[i-1][j-v]+w 今回の品物も選ぶ場合

for i in range(1, N+1):
    w, v = wv[i-1]
    for j in range(10**3, 0, -1):
        t = [dp[i-1][j], dp[i][j+1]]
        if j-v >= 0:
            t.append(dp[i-1][j-v]+w)
        dp[i][j] = min(t)

ret = 0
for i in range(1, 10**3+1):
    if dp[-1][i] <= W:
        ret = i
print(ret)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[10**9+7] * (10**3+2) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

# w 今回の品物だけ選ぶ場合
# dp[i-1][j] 今回の品物を選ばない場合
# dp[i-1][j-v]+w 今回の品物も選ぶ場合

for i in range(1, N+1):
    w, v = wv[i-1]
    for j in range(10**3, 0, -1):
        t = [dp[i-1][j], dp[i][j+1]]
        if j <= v:
            t.append(v)
        if j-v >= 0:
            t.append(dp[i-1][j-v]+w)
        dp[i][j] = min(t)

ret = 0
for i in range(1, 10**3+1):
    if dp[-1][i] <= W:
        ret = i
print(ret)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[10**9+7] * (10**3+1) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

# w 今回の品物だけ選ぶ場合
# dp[i-1][j] 今回の品物を選ばない場合
# dp[i-1][j-v]+w 今回の品物も選ぶ場合

for i in range(1, N+1):
    for j in range(1, 10**3+1):
        w, v = wv[i-1]
        if j <= v:
            dp[i][j] = w
        t = [dp[i-1][j], dp[i][j]]
        if j-v >= 0:
            t.append(dp[i-1][j-v]+w)
        dp[i][j] = min(t)

ret = 0
for i in range(1, 10**3+1):
    if dp[-1][i] <= W:
        ret = i
print(ret)

Submission status: Wrong Answer

Solution code:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[10**9+7] * (10**3+1) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

# dp[i-1][j] 今回の品物は選ばない場合
# dp[i-1][j-v]+w 今回の品物を選ぶ場合

for i in range(1, N+1):
    for j in range(1, 10**3+1):
        w, v = wv[i-1]
        if j <= v:
            dp[i][j] = w
        t = [dp[i-1][j], dp[i][j]]
        if j-v >= 0:
            t.append(dp[i-1][j-v]+w)
        dp[i][j] = min(t)

ret = 0
for i in range(1, 10**3+1):
    if dp[-1][i] <= W:
        ret = i
print(ret)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
import copy

INF = 10 ** 9 + 7
N, W = map(int, input().split())
weight = []
value = []
for i in range(N):
    tempW, tempV = map(int, input().split())
    weight.append(tempW)
    value.append(tempV)

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

for i in range(1, N + 1):
    for l in range(N * 300 + 1):
        if l - value[i - 1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - value[i - 1]] + weight[i - 1])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N * 300 + 1):
    if dp[N][i] <= W:
        ans = i
print(ans)