list map int input split list map int input split for in range for in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
n,w=list(map(int,input().split()))
p=[0]*n
p=list(map(int,input().split()))
A=[[0]*(w+1) for i in range(n+1)]
for i in range(1,n+1):
for j in range(1,w+1):
if j-p[i-1]>=0:
A[i][j]=max(A[i-1][j],A[i-1][j-p[i-1]]+p[i-1])
else:
A[i][j]=A[i-1][j]
print(A[-1][-1])