Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, W):
    dp = [-1] * (W + 1)
    dp[0] = 0
    for i in range(n):
        wi, vi = map(int, input().split())
        dp_ = list(dp)
        for w in range(W + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= W and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wv, W):
    dp = [-1] * (W + 1)
    dp[0] = 0
    for wi, vi in wv:
        dp_ = list(dp)
        for w in range(W + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= W and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5
wv = [[int(x) for x in input().split()] for _ in range(n)]

print(f(n, wv, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

def f(n, wv, W):
    dp = [0] * (W + 1)
    for wi, vi in wv:
        for w in range(W, wi - 1, -1):
            dp[w] = max(dp[w], dp[w - wi] + vi)
    return(dp[-1])

n, w = map(int, input().split()) # 1 <= n <= 100, 1 <= w <= 10^5
wv = [[int(x) for x in input().split()] for _ in range(n)]

print(f(n, wv, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

import sys
input = sys.stdin.readline

def f(n, wv, W):
    dp = [0] * (W + 1)
    for wi, vi in wv:
        for w in range(W, wi - 1, -1):
            dp[w] = max(dp[w], dp[w - wi] + vi)
    return(dp[-1])

n, w = map(int, input().split()) # 1 <= n <= 100, 1 <= w <= 10^5
wv = [[int(x) for x in input().split()] for _ in range(n)]

print(f(n, wv, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, W):
    dp = [0] * (W + 1)
    for i in range(n):
        wi, vi = map(int, input().rstrip().split())
        for w in range(W, wi - 1, -1):
            dp[w] = max(dp[w], dp[w - wi] + vi)
    return(dp[-1])

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, W):
    dp = [0] * (W + 1)
    wv = [list(map(int, input().rstrip().split())) for _ in range(n)]
    for wi, vi in wv:
        for w in range(W, wi - 1, -1):
            dp[w] = max(dp[w], dp[w - wi] + vi)
    return(dp[-1])

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [0] * (wlimit + 1)
    wv = [list(map(int, input().rstrip().split())) for _ in range(n)]
    for wi, vi in wv:
        dp_ = list(dp)
        for w in range(wlimit + 1):
            v_ = dp[w] if w - wi < 0 else dp[w - wi] + vi
            dp_[w] = max(dp[w], v_)
        dp = dp_
    return(dp[-1])

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wv, wlimit):
    dp = [[0] * (wlimit + 1) for _ in range(n + 1)]
    for i, (wi, vi) in enumerate(wv):
        for w in range(wlimit + 1):
            w_ = w - wi
            v_ = dp[i][w] if w_ < 0 else dp[i][w_] + vi
            dp[i + 1][w] = max(dp[i][w], v_)
    return(dp[-1][-1])

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5
wv = [list(map(int, input().rstrip().split())) for _ in range(n)]

print(f(n, wv, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [[0] * (wlimit + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        for w in range(wlimit + 1):
            w_ = w - wi
            v_ = dp[i - 1][w] if w_ < 0 else dp[i - 1][w_] + vi
            dp[i][w] = max(dp[i - 1][w], v_)
    return(dp[i][-1])

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [[-1] * (wlimit + 1) for _ in range(n + 1)]
    dp[0][0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        for w in range(wlimit + 1):
            if dp[i - 1][w] >= 0:
                w_ = w + wi
                v_ = dp[i - 1][w] + vi
                if w_ <= wlimit:
                    if dp[i - 1][w_] < v_:
                        dp[i][w_] = v_
                if dp[i][w] < dp[i - 1][w]:
                    dp[i][w] = dp[i - 1][w]
    return(max(dp[i]))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    # dp[i][w]
    #   i番目の品物までで w を超えないように選んだ最大価値
    dp = { 0: 0 }   # { <sum weight>: <sum value> }
    for i in range(1, n + 1):
        dp_ = {}
        wi, vi = map(int, input().rstrip().split())
        for w, v in dp.items():
            w_ = w + wi
            v_ = v + vi
            if w_ <= wlimit and (w_ not in dp or dp[w_] < v_):
                dp_[w_] = v_
        dp.update(dp_)
    return(max(dp.values()))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))


Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))