s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s979107813 | p03780 | u310678820 | 1576434254 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1473 | 426504 | 1256 | class cumsum:
def __init__(self, A):
self.n = len(A)
self.data = [0]*self.n
for i in range(self.n):
self.data[i] = self.data[i-1]+A[i]
def query(self, l, r):
if n<=l:
return 0
if r<0:
return 0
if l<0:
x = 0
else:
x = self.data[l]
if r>=self.n:
y = self.data[-1]
else:
y = self.data[r]
return y-x
N, K = map(int, input().split())
a = list(map(int, input().split()))
a = [i for i in a if i<=K]
N = len(a)
dp1 = [[0]*(K+1) for _ in range(N+1)]
dp2 = [[0]*(K+1) for _ in range(N+1)]
dp1[-1][0] = 1
for i in range(-1, N-1):
for j in range(K):
if j+a[i+1]<=K:
dp1[i+1][j+a[i+1]]|=dp1[i][j]
dp1[i+1][j]|=dp1[i][j]
a.reverse()
dp2[-1][0] = 1
for i in range(-1, N-1):
for j in range(K):
if j+a[i+1]<=K:
dp2[i+1][j+a[i+1]]|=dp2[i][j]
dp2[i+1][j]|=dp2[i][j]
dp2.reverse()
ans = 0
a.reverse()
for i in range(N):
x = dp1[i-1]
y = dp2[(i+2)%(N+1)]
sy = cumsum(y)
for j in range(K+1):
if x[j]:
if sy.query(K-a[i]-1-j, K-1-j):
ans+=1
break
print(N-ans)
|
s527490876 | p03780 | u819048695 | 1575837163 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1552 | 60892 | 569 | import itertools
def fff(x):
dp=[0]*k
dp[0]=1
for u in itertools.chain(a[:x],a[x+1:]):
h=dp[:]
for i in range(u,k):
h[i]=h[i]|dp[i-u]
dp=h
cnt=0
for i in range(k-a[x],k):
cnt+=dp[i]
if cnt==0:
return True
else:
return False
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
low=0
high=n-1
while high-low>1:
mid=(high+low)//2
if fff(mid): #不必要
low=mid
else:
high=mid
if fff(high):
print(high+1)
else:
print(low+1) |
s301231111 | p03780 | u819048695 | 1575836893 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1301 | 61916 | 591 | import itertools
def fff(x):
dp=[0]*k
dp[0]=1
for u in itertools.chain(a[:x],a[x+1:]):
h=dp[:]
for i in range(u,k):
h[i]=max(h[i],dp[i-u])
dp=h
for i in range(k-a[x],k):
if dp[i]==1:
return False
break
else:
return True
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
low=0
high=n-1
while high-low>1:
mid=(high+low)//2
if fff(mid): #不必要
low=mid
else:
high=mid
if fff(high):
print(high+1)
else:
print(low+1)
|
s726494935 | p03780 | u819048695 | 1573607314 | Python | PyPy3 (2.4.0) | py | Runtime Error | 168 | 38384 | 496 | import itertools
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
#必要ないならTrueを返す
def test(i):
b=itertools.chain(a[:i],a[i+1:])
dp=[False]*k
dp[0]=True
for u in b:
dp[u:]=np.logical_or(dp[u:],dp[:-u])
return not any(dp[-a[i]:])
low=0
high=n-1
while high-low>1:
mid=(high+low)//2
if test(mid):
low=mid
else:
high=mid
if test(high):
print(high+1)
else:
print(high) |
s574100359 | p03780 | u819048695 | 1573493001 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2107 | 58716 | 718 | def f(x):
global a
dp=[0]*k
dp[0]=1
for i in range(n):
if i==x:
continue
else:
h=[0]*k
b=a[i]
for i in range(k):
if dp[i]==1:
h[i]=1
if i+b<k:
h[i+b]=1
dp=h
for i in range(k-a[x],k):
if dp[i]==1:
return True
else:
return False
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
low=0
high=n-1
while high>low+1:
h=(high+low)//2
if f(h):
high=h
else:
low=h
if f(low):
print(max(0,low-1)+1)
else:
if f(high):
print(low+1)
else:
print(high+1) |
s544659942 | p03780 | u467736898 | 1572929557 | Python | Python (3.4.3) | py | Runtime Error | 1857 | 2089796 | 639 | import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp1 = np.zeros((N+1, K), dtype=bool)
dp1[0][0] = 1
for i, a in enumerate(A, 1):
dp1[i, :] = dp1[i-1, :]
dp1[i, a:] += dp1[i-1, :-a]
dp2 = np.zeros((N+1, K), dtype=bool)
dp2[N][0] = 1
for i, a in zip(range(N-1, -1, -1), A[::-1]):
dp2[i, :] = dp2[i+1, :]
dp2[i, a:] += dp2[i+1, :-a]
ans = 0
for a, d1, d2 in zip(A, dp1[:-1], dp2[1:]):
d2_ = np.zeros(K+a, dtype=np.int32)
d2_[a:] = d2
d2_cum = np.cumsum(d2_)
d2_diff = d2_cum[a:] - d2_cum[:-a]
d = d2_diff[::-1] * d1
if (d == 0).all():
ans += 1
print(ans)
|
s176690770 | p03780 | u803848678 | 1572905594 | Python | PyPy3 (2.4.0) | py | Runtime Error | 186 | 39920 | 627 | import numpy as np
def main():
def check(m):
DP = np.full(k+1, False)
DP[0] = True
for i in range(n):
if i == m:
continue
DP[a[i]:] = np.logical_or(DP[a[i]:], DP[:k+1-a[i]])
return any(DP[i] for i in range(k-a[m], k))
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = [i for i in a if i <k]
a.sort()
n = len(a)
left = -1
right = n
while right-left > 1:
mid = (right+left)//2
if check(mid):
right = mid
else:
left = mid
print(right)
main() |
s332125690 | p03780 | u803848678 | 1572903364 | Python | Python (3.4.3) | py | Runtime Error | 841 | 598876 | 897 | import numpy as np
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = [i for i in a if i <k]
n = len(a)
DP1 = [[False]*(k+1) for i in range(n+1)]
DP1 = np.full((n+1, k+1), False)
DP1[0][0] = True
DP2 = [[False]*(k+1) for i in range(n+1)]
DP2 = np.full((n+1, k+1), False)
DP2[0][0] = True
for i in range(n):
DP1[i+1] = DP1[i]
DP1[i+1][a[i]:] |= DP1[i][:k-a[i]+1]
DP2[i+1] = DP2[i]
DP2[i+1][a[n-1-i]:] |= DP2[i][:k-a[n-1-i]+1]
hoge = []
for i in range(n+1):
q = [0]
for j in range(k+1):
q.append(q[-1]+int(DP2[i][j]))
hoge.append(q)
ans = 0
for i in range(n):
use = False
for j in range(k+1):
if not DP1[i][j]:
continue
left = max(0, k-a[i]-j)
right = k-j
if hoge[n-i-1][right] - hoge[n-i-1][left]:
use = True
break
if not use:
ans += 1
print(ans) |
s984961077 | p03780 | u042802884 | 1572595652 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2132 | 465032 | 826 | N,K=map(int,input().split())
a=[None]
a.extend(list(map(int,input().split())))
# K以上の整数が書かれたカードは,不必要ではない。
# print(a) #DB
# dp[i][j]=i枚目のカードを使用して合計がjになったことがあるか(1<=i<=N,0<=j<=2K-2)
dp=[[False for j in range(2*K-1)] for i in range(N+1)];dp[0]=None
for i2 in range(1,N+1):
t=a[i2]
dp[i2][t]=True
for i1 in range(1,i2):
for j in range(2*K-2,0,-1):
if dp[i1][j] and j+t<=2*K-2:
dp[i1][j+t]=dp[i2][j+t]=True
# print(dp) #DB
ans=0
for i in range(1,N+1):
t=a[i]
if t>=K:
continue
else:
f=True
for j in range(K,K+t):
if dp[i][j]:
f=False
break
if f:
# print(t,f)
ans+=1
print(ans) |
s598170805 | p03780 | u892251744 | 1570240000 | Python | Python (3.4.3) | py | Runtime Error | 2129 | 414580 | 753 | N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [[10 ** 11 for _ in range(2*K-1)] for _ in range(N+1)]
for i in range(N+1):
dp[i][0] = 10 ** 10
for i in range(N):
for j in range(K):
if dp[i][j] < 10 ** 10 + 1:
dp[i+1][j] = min(dp[i+1][j], dp[i][j])
if j + a[i] <= 2*(K-1):
dp[i+1][j+a[i]] = min(dp[i+1][j+a[i]], dp[i][j], a[i])
dp_last = dp[-1][K:]
ans = 0
i = 0
prev = 0
for i in range(N):
if a[i] == prev:
i += 1
ans += 1
continue
else:
prev = a[i]
ok = 0
for j in range(a[i]):
if dp_last[j] <= a[i]:
ok = 1
break
if ok:
break
else:
ans += 1
print(ans)
|
s354134707 | p03780 | u892251744 | 1570236533 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2144 | 632968 | 1173 | def main():
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
num = [0] * K
c = 0
ok = float('inf')
for i, ai in enumerate(a):
if ai >= K:
a = a[:i]
else:
num[ai] += 1
c += ai
if c >= K:
ok = i - num[ai] + 1
if not a:
print(0)
exit()
n = len(a)
if ok > n:
ok = n
ng = -1
mid = (ok + ng) // 2
while ok - ng > 1:
flg = 0
dp = [[0 for _ in range(K)] for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(K):
if dp[i][j] == 1:
if i != mid:
if j + a[i] <= K-1:
dp[i+1][j+a[i]] = 1
dp[i+1][j] = 1
for i in range(-1, -a[mid]-1, -1):
if dp[-1][i] == 1:
flg = 1
break
if flg:
ok = mid
else:
ng = mid
mid = (ok + ng) // 2
if ng == -1:
print(0)
exit()
print(sum(num[:a[ng]+1]))
if __name__ == '__main__':
main()
|
s285963194 | p03780 | u310678820 | 1570060386 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2160 | 817544 | 1307 | N, K = map(int, input().split())
a = sorted(list(map(int, input().split())))
for i in range(N):
if a[i]<=K:
n = i
else:
break
if n == 0:
print(0)
exit()
N = n+1
a = a[:N]
dp1 = [[0]*(K+1) for _ in range(N+1)]
dp2 = [[0]*(K+1) for _ in range(N+1)]
dp1[0][0] = 1
dp2[-1][0] = 1#i~Nまで使う
for i in range(N):
for j in range(K+1):
if j>=a[i]:
dp1[i+1][j] = max(dp1[i][j], dp1[i][j-a[i]])
else:
dp1[i+1][j] = dp1[i][j]
for i in range(N)[::-1]:
for j in range(K+1):
if j>=a[i]:
dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-a[i]])
else:
dp2[i][j] = dp2[i+1][j]
S1 = [[0]*(K+1) for _ in range(N+1)]
S2 = [[0]*(K+1) for _ in range(N+1)]
for i in range(N+1):
S1[i][0], S2[i][0] = dp1[i][0], dp2[i][0]
for i in range(N+1):
for j in range(K):
S1[i][j+1] = S1[i][j]+dp1[i][j+1]
S2[i][j+1] = S2[i][j]+dp2[i][j+1]
ans = 0
for i in range(N):
need = False
for j in range(K):
if dp1[i][j]:
if K-j-a[i]>0:
l = K-j-a[i]-1
if S2[i+1][K-j-1]-S2[i+1][l]:
need = True
else:
if S2[i+1][K-j]:
need = True
if not need:
ans+=1
print(ans)
|
s794211261 | p03780 | u588341295 | 1569390595 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2194 | 1458428 | 1599 | # -*- coding: utf-8 -*-
import sys
from collections import defaultdict
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N, K = MAP()
A = LIST()
# 部分和DPを変形させて、その値になるのに使われた値の集合を持っておく
dp = defaultdict(set)
dp[0].add(0)
for i in range(N):
for j in range(K-1, -1, -1):
if len(dp[j]):
dp[j+A[i]] |= dp[j]
dp[j+A[i]].add(A[i])
raise Exception
# 和がK未満の集合はこの後のチェックで使わないので削る
dp = sorted(dp.items())
keys, sets = zip(*dp)
idx = bisect_left(keys, K)
keys = keys[idx:]
sets = sets[idx:]
ans = 0
for i in range(N):
for k, s in zip(keys, sets):
# A[i]減らしたらK未満になる状況で、一度でもA[i]が使われていれば必要
if k-A[i] < K and A[i] in s:
break
else:
# 該当するどの集合でも、一度も使われていなければ不要
ans += 1
print(ans)
|
s444203798 | p03780 | u423585790 | 1567101238 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2129 | 410760 | 2255 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b = LS()
if a == b:
print("H")
else:
print("D")
return
#B
def B():
w, a, b = LI()
a, b = min(a, b), max(a, b)
if w + a >= b:
print(0)
return
print(b-a-w)
return
#C
def C():
n = II()
x = 0
for i in range(1, 10 ** 5):
x += i
if n <= x:
print(i)
return
return
#D
def D():
n, k = LI()
a = LI()
a.sort()
ok = n
ng = -1
def f(x):
dp = [[False] * (k) for _ in range(n)]
dp[0][0] = True
for i in range(n):
dpi = dp[i]
dpi1 = dp[i - 1]
ai = a[i]
for j in range(k):
if i == x:
dpi[j] |= dpi1[j]
else:
if j >= a[i]:
dpi[j] |= dpi1[j - ai]
dpi[j] |= dpi1[j]
for j in range(k - a[x], k):
if dpi[j]:
return True
return False
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ng + 1)
return
#Solve
if __name__ == '__main__':
D()
|
s623327021 | p03780 | u423585790 | 1567100866 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2124 | 334088 | 2224 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b = LS()
if a == b:
print("H")
else:
print("D")
return
#B
def B():
w, a, b = LI()
a, b = min(a, b), max(a, b)
if w + a >= b:
print(0)
return
print(b-a-w)
return
#C
def C():
n = II()
x = 0
for i in range(1, 10 ** 5):
x += i
if n <= x:
print(i)
return
return
#D
def D():
n, k = LI()
a = LI()
a.sort()
ok = n
ng = -1
def f(x):
dp = [[False] * (k) for i in range(n)]
dp[0][0] = True
for i in range(n):
dpi = dp[i]
dpi1 = dp[i - 1]
for j in range(k):
if i == x:
dpi[j] |= dpi1[j]
else:
if j >= a[i]:
dpi[j] |= dpi1[j - a[i]]
dpi[j] |= dpi1[j]
for i in range(k - a[x], k):
if dpi[i]:
return True
return False
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ng + 1)
return
#Solve
if __name__ == '__main__':
D()
|
s696337125 | p03780 | u423585790 | 1567100825 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2126 | 346888 | 2279 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b = LS()
if a == b:
print("H")
else:
print("D")
return
#B
def B():
w, a, b = LI()
a, b = min(a, b), max(a, b)
if w + a >= b:
print(0)
return
print(b-a-w)
return
#C
def C():
n = II()
x = 0
for i in range(1, 10 ** 5):
x += i
if n <= x:
print(i)
return
return
#D
def D():
n, k = LI()
a = LI()
a.sort()
ok = n - 1
ng = -1
def f(x):
dp = [[False] * (k) for i in range(n)]
dp[0][0] = True
for i in range(n):
dpi = dp[i]
dpi1 = dp[i - 1]
for j in range(k):
if i == x:
dpi[j] |= dpi1[j]
else:
if j >= a[i]:
dpi[j] |= dpi1[j - a[i]]
dpi[j] |= dpi1[j]
for i in range(k - a[x], k):
if dpi[i]:
return True
return False
if sum(a) <= k:
print(n)
return
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ng + 1)
return
#Solve
if __name__ == '__main__':
D()
|
s860668982 | p03780 | u423585790 | 1567100628 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2125 | 349832 | 2278 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b = LS()
if a == b:
print("H")
else:
print("D")
return
#B
def B():
w, a, b = LI()
a, b = min(a, b), max(a, b)
if w + a >= b:
print(0)
return
print(b-a-w)
return
#C
def C():
n = II()
x = 0
for i in range(1, 10 ** 5):
x += i
if n <= x:
print(i)
return
return
#D
def D():
n, k = LI()
a = LI()
a.sort()
ok = n - 1
ng = 0
def f(x):
dp = [[False] * (k) for i in range(n)]
dp[0][0] = True
for i in range(n):
dpi = dp[i]
dpi1 = dp[i - 1]
for j in range(k):
if i == x:
dpi[j] |= dpi1[j]
else:
if j >= a[i]:
dpi[j] |= dpi1[j - a[i]]
dpi[j] |= dpi1[j]
for i in range(k - a[x], k):
if dpi[i]:
return True
return False
if sum(a) <= k:
print(n)
return
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ng + 1)
return
#Solve
if __name__ == '__main__':
D()
|
s867125714 | p03780 | u423585790 | 1567100477 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2122 | 301320 | 2249 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b = LS()
if a == b:
print("H")
else:
print("D")
return
#B
def B():
w, a, b = LI()
a, b = min(a, b), max(a, b)
if w + a >= b:
print(0)
return
print(b-a-w)
return
#C
def C():
n = II()
x = 0
for i in range(1, 10 ** 5):
x += i
if n <= x:
print(i)
return
return
#D
def D():
n, k = LI()
a = LI()
a.sort()
ok = n - 1
ng = 0
def f(x):
dp = [[False] * (k) for i in range(n)]
dp[0][0] = True
for i in range(n):
for j in range(k):
if i == x:
dp[i][j] |= dp[i - 1][j]
else:
if j >= a[i]:
dp[i][j] |= dp[i - 1][j - a[i]]
dp[i][j] |= dp[i - 1][j]
for i in range(k - a[x], k):
if dp[-1][i]:
return True
return False
if sum(a) <= k:
print(n)
return
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ng + 1)
return
#Solve
if __name__ == '__main__':
D()
|
s492855097 | p03780 | u423585790 | 1567100394 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2124 | 301576 | 2288 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b = LS()
if a == b:
print("H")
else:
print("D")
return
#B
def B():
w, a, b = LI()
a, b = min(a, b), max(a, b)
if w + a >= b:
print(0)
return
print(b-a-w)
return
#C
def C():
n = II()
x = 0
for i in range(1, 10 ** 5):
x += i
if n <= x:
print(i)
return
return
#D
def D():
n, k = LI()
a = LI()
a.sort()
ok = n - 1
ng = 0
def f(x):
dp = [[False] * (k + 1) for i in range(n)]
for i in range(n):
dp[i][0] = True
for i in range(n):
for j in range(k + 1):
if i == x:
dp[i][j] |= dp[i - 1][j]
else:
if j >= a[i]:
dp[i][j] |= dp[i - 1][j - a[i]]
dp[i][j] |= dp[i - 1][j]
for i in range(k - a[x], k):
if dp[-1][i]:
return True
return False
if sum(a) <= k:
print(n)
return
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ng + 1)
return
#Solve
if __name__ == '__main__':
D()
|
s693916019 | p03780 | u423585790 | 1567100330 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2122 | 301320 | 2232 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b = LS()
if a == b:
print("H")
else:
print("D")
return
#B
def B():
w, a, b = LI()
a, b = min(a, b), max(a, b)
if w + a >= b:
print(0)
return
print(b-a-w)
return
#C
def C():
n = II()
x = 0
for i in range(1, 10 ** 5):
x += i
if n <= x:
print(i)
return
return
#D
def D():
n, k = LI()
a = LI()
a.sort()
ok = n
ng = 0
def f(x):
dp = [[False] * (k + 1) for i in range(n)]
for i in range(n):
dp[i][0] = True
for i in range(n):
for j in range(k + 1):
if i == x:
dp[i][j] |= dp[i - 1][j]
else:
if j >= a[i]:
dp[i][j] |= dp[i - 1][j - a[i]]
dp[i][j] |= dp[i - 1][j]
for i in range(k - a[x], k):
if dp[-1][i]:
return True
return False
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if f(mid):
ok = mid
else:
ng = mid
print(ng + 1)
return
#Solve
if __name__ == '__main__':
D()
|
s904990853 | p03780 | u947883560 | 1566065401 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 199540 | 1053 | #!/usr/bin/env python3
import sys
INF = float("inf")
def solve(N: int, K: int, a: "List[int]"):
a.sort()
count = 0
ng = -1
ok = N
while abs(ok - ng) > 1:
j = (ok + ng) // 2
A = a[:j]+a[j+1:]
# print(A)
DP = [[False]*K for _ in range(N-1)]
if A[0] < K:
DP[0][A[0]] = True
for i in range(1, N-1):
for k in range(K):
if DP[i-1][k] == True:
DP[i][k] = True
if k + A[i] < K:
DP[i][k+A[i]] = DP[i-1][k]
if any(DP[-1][max(K-a[j], 0):]):
ok = j
else:
ng = j
print(ok)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, a)
if __name__ == '__main__':
main()
|
s277825414 | p03780 | u947883560 | 1566065289 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 200948 | 1076 | #!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")
def solve(N: int, K: int, a: "List[int]"):
a.sort()
# print(a)
count = 0
ng = -1
ok = N
while abs(ok - ng) > 1:
j = (ok + ng) // 2
A = a[:j]+a[j+1:]
# print(A)
DP = [[False]*K for _ in range(N-1)]
DP[0][A[0]] = True
for i in range(1, N-1):
for k in range(K):
if DP[i-1][k] == True:
DP[i][k] = True
if k + A[i] < K:
DP[i][k+A[i]] = DP[i-1][k]
if any(DP[-1][max(K-a[j], 0):]):
ok = j
else:
ng = j
print(ok)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, a)
if __name__ == '__main__':
main()
|
s532241748 | p03780 | u947883560 | 1566064424 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 201204 | 1175 | #!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")
def solve(N: int, K: int, a: "List[int]"):
a.sort()
count = 0
ng = -1
ok = N
while abs(ok - ng) > 1:
j = (ok + ng) // 2
A = a[:j]+a[j+1:]
# print(A)
DP = [[False]*K for _ in range(N-1)]
for i in range(N-1):
if A[i] < K:
DP[i][A[i]] = True
if i == 0:
continue
for k in range(K):
DP[i][k] = DP[i-1][k] or DP[i][k]
if 0 <= k - A[i] < K:
DP[i][k] = DP[i][k] or DP[i-1][k-A[i]]
# print(*DP, sep="\n")
# print("")
if any(DP[N-2][K-a[j]:]):
ok = j
else:
ng = j
print(ok)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, a)
if __name__ == '__main__':
main()
|
s387012452 | p03780 | u947883560 | 1566064408 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 201588 | 1163 | #!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")
def solve(N: int, K: int, a: "List[int]"):
count = 0
ng = -1
ok = N
while abs(ok - ng) > 1:
j = (ok + ng) // 2
A = a[:j]+a[j+1:]
# print(A)
DP = [[False]*K for _ in range(N-1)]
for i in range(N-1):
if A[i] < K:
DP[i][A[i]] = True
if i == 0:
continue
for k in range(K):
DP[i][k] = DP[i-1][k] or DP[i][k]
if 0 <= k - A[i] < K:
DP[i][k] = DP[i][k] or DP[i-1][k-A[i]]
# print(*DP, sep="\n")
# print("")
if any(DP[N-2][K-a[j]:]):
ok = j
else:
ng = j
print(ok)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, a)
if __name__ == '__main__':
main()
|
s583000110 | p03780 | u947883560 | 1566064224 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 199412 | 1084 | #!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")
def solve(N: int, K: int, a: "List[int]"):
count = 0
for j in range(N):
A = a[:j]+a[j+1:]
# print(A)
DP = [[False]*K for _ in range(N-1)]
for i in range(N-1):
if A[i] < K:
DP[i][A[i]] = True
if i == 0:
continue
for k in range(K):
DP[i][k] = DP[i-1][k] or DP[i][k]
if 0 <= k - A[i] < K:
DP[i][k] = DP[i][k] or DP[i-1][k-A[i]]
# print(*DP, sep="\n")
# print("")
if any(DP[N-2][K-a[j]:]):
count += 1
print(N-count)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, a)
if __name__ == '__main__':
main()
|
s072485993 | p03780 | u794250528 | 1565900606 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2182 | 1030536 | 512 | n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
def ok(x):
dp = [[0] * k for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
for j in range(k):
dp[i + 1][j] += dp[i][j]
if i != x and j + a[i] < k:
dp[i + 1][j + a[i]] += dp[i][j]
return any(dp[n][i] > 0 for i in range(k - a[x], k))
lo = -1
hi = n
while abs(hi - lo) > 1:
mi = (hi + lo) // 2
if ok(mi):
hi = mi
else:
lo = mi
print(hi) |
s280492144 | p03780 | u634461820 | 1563312145 | Python | Python (3.4.3) | py | Runtime Error | 2127 | 236460 | 957 | #import numpy as np
MAX_INT = int(10e10)
N,K = list(map(int,input().split()))
cards = list(map(int,input().split()))
cards.sort()
cards += [MAX_INT]
#print(cards)
memo = [None]*5010
dp = [[0]*K for i in range(N+2)]
left = -1
right = N
while right - left > 1:
middle = (left+right)//2
if memo[cards[middle]] == True or cards[middle] >= K:
right = middle
elif memo[cards[middle]] == False:
left = middle
else:
#print(left,right,middle,cards[middle])
for i in range(N+1):
for j in range(K):
if i == middle:
dp[i+1][j] = dp[i][j]
else:
if cards[i] <= j:
dp[i+1][j] = max(dp[i][j],dp[i][j-cards[i]]+cards[i])
else:
dp[i+1][j] = dp[i][j]
#print(dp)
if dp[N][K-1] + cards[middle] >= K:
right = middle
memo[cards[middle]] = True
#print(True)
else:
left = middle
memo[cards[middle]] = False
#print(False)
print(right) |
s043803023 | p03780 | u511965386 | 1563154016 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2111 | 121436 | 436 | N, K = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
ret = [0] * N
def rec(i, s, m) :
if s >= K :
if s - m < K :
return True
return False
if i == N :
return False
c1 = rec(i + 1, s + a[i], min(m, a[i]))
c2 = rec(i + 1, s, m)
if c1 :
ret[i] = 1
return (c1 or c2)
rec(0, 0, float('inf'))
print(N - sum(ret)) |
s657315607 | p03780 | u511965386 | 1563153864 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2111 | 143236 | 455 | N, K = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
ret = [0] * N
def rec(i, s, m) :
print(i, s, m)
if s >= K :
if s - m < K :
return True
return False
if i == N :
return False
c1 = rec(i + 1, s + a[i], min(m, a[i]))
c2 = rec(i + 1, s, m)
if c1 :
ret[i] = 1
return (c1 or c2)
rec(0, 0, float('inf'))
print(N - sum(ret)) |
s478371709 | p03780 | u456353530 | 1562784777 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2170 | 1117832 | 982 | N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(N):
if a[-1 -i] < K:
break
ans += 1
n = N - ans
D = []
re = a[0]
cnt = 0
for i in range(n):
if re == a[i]:
cnt += 1
else:
D.append([re, cnt])
cnt = 1
re = a[i]
else:
D.append([re, cnt])
L = [{} for _ in range(2 * K)]
M = [[0] * (2 * K) for _ in range(2 * K)]
for i in D:
for j in range(i[1]):
if i[0] * (j + 1) >= 2 * K:
break
L[i[0] * (j + 1)][i[0]] = 1
M[i[0] * (j + 1)][i[0]] = 1
for i in D:
for j in range(i[1]):
for k in range(K):
t = i[0] * (j + 1)
if k + t >= 2 * K:
break
if len(L[k]) > 0:
if M[k][t] == 0:
for l in L[k].keys():
M[k + t][l] = 1
L[k + t][l] = 1
M[k + t][t] = 1
L[k + t][l] = 1
for i in D:
for j in range(K, K + i[0]):
if len(L[j]) > 0 and M[j][i[0]] == 1:
ans += i[1]
break
print(N - ans)
|
s268264780 | p03780 | u167751176 | 1561164003 | Python | Python (3.4.3) | py | Runtime Error | 2117 | 215668 | 774 | def main():
N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
l, r = 0, N-1
while l < r:
m = (l+r)>>1
p = True
if m == 0 and solve(N, K, A[1:], A[0]):
l = m+1
continue
if solve(N, K, A[:m]+A[m+1:], A[m]):
l = m+1
else:
r = m
if l == N-1 and solve(N, K, A[:N-1], A[N-1]):
l = N
print(l)
def solve(n, k, a, ai):
dp = [[False for _ in range(k+1)] for _ in range(n)]
dp[0][0] = True
if a[0] > k:
dp[0][k] = True
else:
dp[0][a[0]] = True
for i in range(1, n-1):
for j in range(k-1):
if not dp[i-1][j]:
continue
dp[i][j] = True
if j + a[i] > k:
dp[i][k] = True
else:
dp[i][j+a[i]] = True
return not any(map(lambda j: dp[n-2][j], range(k-ai, k)))
if __name__ == '__main__':
main() |
s852999696 | p03780 | u167751176 | 1561163819 | Python | Python (3.4.3) | py | Runtime Error | 2118 | 215668 | 709 | def main():
N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
l, r = 0, N-1
while l < r:
m = (l+r)>>1
p = True
if solve(N, K, A[:m]+A[m+1:], A[m]):
l = m+1
else:
r = m
if l == N-1 and solve(N, K, A[:N-1], A[N-1]):
l = N
print(l)
def solve(n, k, a, ai):
dp = [[False for _ in range(k+1)] for _ in range(n)]
dp[0][0] = True
if a[0] > k:
dp[0][k] = True
else:
dp[0][a[0]] = True
for i in range(1, n-1):
for j in range(k-1):
if not dp[i-1][j]:
continue
dp[i][j] = True
if j + a[i] > k:
dp[i][k] = True
else:
dp[i][j+a[i]] = True
return not any(map(lambda j: dp[n-2][j], range(k-ai, k)))
if __name__ == '__main__':
main() |
s770571126 | p03780 | u059210959 | 1558308944 | Python | Python (3.4.3) | py | Runtime Error | 2117 | 218060 | 1088 | # encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
mod = 10**9+7
N,K = map(int,input().split())
a = [int(i) for i in input().split()]
cnt = 0
# if sum(a) < K:
# cnt = len(a)
# print(cnt)
# exit()
# a.sort()
def solve(rest_min,b):
dp = [[False for i in range(K+1)]for j in range(N-1)]
for i in range(N-1):
if b[i] < K:
dp[i][b[i]] = True
for j in range(K+1):
if dp[i-1][j]:
dp[i][j] = True
if j+b[i] < K:
dp[i][j+b[i]] = True
# print(dp)
for j in range(rest_min,K+1):
if dp[-1][j]:
return True
return False
for i in range(N):
rest_min = K-a[i]
rest_max = K-1
b = copy.deepcopy(a)
b.remove(a[i])
if solve(rest_min,b):
pass
else:
cnt += 1
"""
もし残りのカードでこの範囲の数を作れれば必要
無理ならcnt += 1
"""
print(cnt)
|
s610713062 | p03780 | u059210959 | 1558307640 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 6796 | 1079 | # encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
mod = 10**9+7
N,K = map(int,input().split())
a = [int(i) for i in input().split()]
cnt = 0
# if sum(a) < K:
# cnt = len(a)
# print(cnt)
# exit()
a.sort()
#あるインデックスのものをのぞいて,その値を含むようなものが存在するか調べる
def solve(rest_min,rest_max,b,i,sum):
if i == len(b):
return rest_min < sum < rest_max
if sum > rest_max:
return False
if(solve(rest_min,rest_max,b,i+1,sum)):
return True
if(solve(rest_min,rest_max,b,i+1,sum+b[i])):
return True
return False
for i in range(N):
rest_min = K-a[i]
rest_max = K-1
b = copy.deepcopy(a)
b.remove(a[i])
if solve(rest_min,rest_max,b,i=0,sum=0):
pass
else:
cnt += 1
"""
もし残りのカードでこの範囲の数を作れれば必要
無理ならcnt += 1
"""
print(cnt)
|
s857349453 | p03780 | u059210959 | 1558307561 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 6736 | 1035 | # encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
mod = 10**9+7
N,K = map(int,input().split())
a = [int(i) for i in input().split()]
cnt = 0
# if sum(a) < K:
# cnt = len(a)
# print(cnt)
# exit()
a.sort()
#あるインデックスのものをのぞいて,その値を含むようなものが存在するか調べる
def solve(rest_min,rest_max,b,i,sum):
if i == len(b):
return rest_min < sum < rest_max
if(solve(rest_min,rest_max,b,i+1,sum)):
return True
if(solve(rest_min,rest_max,b,i+1,sum+b[i])):
return True
return False
for i in range(N):
rest_min = K-a[i]
rest_max = K-1
b = copy.deepcopy(a)
b.remove(a[i])
if solve(rest_min,rest_max,b,i=0,sum=0):
pass
else:
cnt += 1
"""
もし残りのカードでこの範囲の数を作れれば必要
無理ならcnt += 1
"""
print(cnt)
|
s309809802 | p03780 | u075012704 | 1556846462 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 1774 | def main():
def accumulate(X):
ret = [X[0]]
for x in X[1:]:
ret.append(ret[-1] + x)
return ret
N, K = map(int, raw_input().split())
A = list(map(int, raw_input().split()))
# K以上の数はすべて必要なのでA未満の数だけを考える
A = sorted([a for a in A if a < K], reverse=True)
N = len(A)
# dp1[i][k] := 1 ~ iまでのカードを使って数kが作れるか
dp1 = [[0] * (K + 1) for i in range(N + 1)]
dp1[0][0] = 1
# dp2[i][k] := N ~ iまでのカードを使って数kが作れるか
dp2 = [[0] * (K + 1) for i in range(N + 1)]
dp2[0][0] = 1
# dpテーブルを計算
for i in range(1, N + 1):
for k in range(K + 1):
dp1[i][k] = max(dp1[i][k], dp1[i - 1][k])
if A[i - 1] <= k:
dp1[i][k] = max(dp1[i][k], dp1[i - 1][k - A[i - 1]])
dp2[i][k] = max(dp2[i][k], dp2[i - 1][k])
if A[N - i] <= k:
dp2[i][k] = max(dp2[i][k], dp2[i - 1][k - A[N - i]])
# 累積和を取っておく
for i in range(N + 1):
dp2[i] = list(accumulate(dp2[i]))
# ansを計算
need = 0
for i in range(1, N + 1):
for k in range(K + 1):
# 1 ~ i番目まででkが作れない
if not dp1[i - 1][k]:
continue
# 1 ~ i番目までだけで必要な条件が作れる
if K - A[i - 1] <= k < K:
need += 1
break
# 範囲外参照
if K - A[i - 1] - k - 1 < 0:
continue
if dp2[N - i][K - k] - dp2[N - i][K - A[i - 1] - k - 1] > 0:
need += 1
break
print(N - need)
main() |
s558309204 | p03780 | u052499405 | 1555637159 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 201324 | 654 | n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)
max_k = min(sum(a), 5000)
def check_needed(index):
memo = [[0] * (max_k + 1) for _ in range(n+1)]
memo[0][0] = 1
for i in range(n):
for j in range(max_k + 1):
if memo[i][j] == 1:
memo[i+1][j] = 1
if i != index:
memo[i+1][j+a[i]] = 1
return (1 in memo[n][max(k-a[index], 0):k])
l = -1
r = n
while r-l > 1:
mid = (l+r) // 2
if not check_needed(mid):
r = mid
else:
l = mid
if sum(a) < k:
print(n)
else:
print(n - r) |
s872211730 | p03780 | u319818856 | 1554499127 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 201076 | 585 | def no_need(N: int, K: int, A: list) -> int:
count = 0
for i in range(N):
dp = [[False] * (K + 1) for _ in range(N)]
dp[0][0] = True
for n, a in enumerate(A[:i] + A[i+1:]):
for k in range(K + 1):
dp[n+1][k] = dp[n][k]
if a <= k:
dp[n+1][k] |= dp[n][k - a]
if not any(dp[N-1][k - A[i]:]):
count += 1
return count
if __name__ == "__main__":
N, K = map(int, input().split())
A = [int(s) for s in input().split()]
ans = no_need(N, K, A)
print(ans)
|
s965559575 | p03780 | u319818856 | 1554495864 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3572 | 620 | def no_need(N: int, K: int, A: list) -> int:
count = 0
for i in range(N):
# s[i] を要素の和が i 以上の部分集合の個数とする。
s = [0] * (K + 1)
s[0] = 1
for a in A[:i] + A[i+1:]:
for k in range(K, -1, -1):
s[min(K, a + k)] += s[k]
s[0] = 0
for k in range(K, 0, -1):
s[k-1] += s[k]
count += 1 if s[K - A[i]] - s[K] == 0 else 0
return count
if __name__ == "__main__":
N, K = map(int, input().split())
A = [int(s) for s in input().split()]
ans = no_need(N, K, A)
print(ans)
|
s494317973 | p03780 | u695811449 | 1554195827 | Python | PyPy3 (2.4.0) | py | Runtime Error | 518 | 53596 | 867 | import sys
import copy
input = sys.stdin.readline
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
SUM=0
for a in A:
SUM+=a
if SUM>=K:
MAX_NO_NEED=a
break
else:
print(N)
sys.exit()
A=[a for a in A if a<K]
L=len(A)
MIN=-1
MAX=A.index(MAX_NO_NEED)-1
while MIN!=MAX:
x=(MIN+MAX+1)//2
base=A[x]
SET={base}
flag=0
for i in range(L):
#print(x,i,SET)
if i==x:
continue
a=A[i]
NSET=copy.copy(SET)
for j in SET:
if K<=a+j<K+base:
flag=1
break
elif a+j<K:
NSET.add(a+j)
if flag==1:
#print(x,SET)
MAX=x-1
break
SET=NSET
else:
MIN=x
continue
print(MIN+1)
|
s896694834 | p03780 | u562016607 | 1545086111 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2124 | 317448 | 1032 | N,K=map(int,input().split())
a=[int(i) for i in input().split()]
if N==1:
if K-a[0]<=0:
print(1)
else:
print(0)
def dp(i):
res=[[0 for k in range(K)] for j in range(N-1)]
L=[]
for j in range(N):
if i!=j:
L.append(j)
for j in range(N-1):
for k in range(K):
if j==0:
if k==a[L[j]] or k==0:
res[j][k]=1
else:
res[j][k]=0
continue
if res[j-1][k]==1:
if k+a[L[j]]<K:
res[j][k+a[L[j]]]=1
res[j][k]=1
return res
def check(i):
table=dp(i)[N-2]
for j in range(max(K-a[i],0),K):
if table[j]==1:
return False
return True
X=sorted([(a[i],i) for i in range(N)])
low=-1
high=N
mid=(low+high)//2
while((high-low)>1):
mid=low+(high-low)//2
#range(low,mid) or range(mid,high)
flag=check(X[mid][1])
if flag:
low=mid
else:
high=mid
print(low+1)
|
s099225767 | p03780 | u562016607 | 1544041426 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2118 | 317064 | 1120 | N,K=map(int,input().split())
a=[int(i) for i in input().split()]
if N==1:
if K-a[0]<=0:
print(1)
else:
print(0)
def dp(i):
res=[[0 for k in range(K)] for j in range(N-1)]
L=[]
for j in range(N):
if i!=j:
L.append(j)
for j in range(N-1):
for k in range(K):
if j==0:
if k==a[L[j]] or k==0:
res[j][k]=1
else:
res[j][k]=0
continue
if res[j-1][k]==1:
if k+a[L[j]]<K:
res[j][k+a[L[j]]]=1
res[j][k]=1
return res
def check(i):
table=dp(i)[N-2]
for j in range(max(K-a[i],0),K):
if table[j]==1:
return False
return True
X=sorted([(a[i],i) for i in range(N)])
low=0
high=N
mid=(low+high)//2
if check(X[N-1][1]):
print(N)
exit()
if not(check(X[0][1])):
print(0)
exit()
while((high-low)>1):
mid=(low+high)//2
#range(low,mid) or range(mid,high)
flag=check(X[mid][1])
if flag:
low=mid
else:
high=mid
print(low+1)
|
s280974298 | p03780 | u562016607 | 1544041417 | Python | Python (3.4.3) | py | Runtime Error | 2117 | 214388 | 1120 | N,K=map(int,input().split())
a=[int(i) for i in input().split()]
if N==1:
if K-a[0]<=0:
print(1)
else:
print(0)
def dp(i):
res=[[0 for k in range(K)] for j in range(N-1)]
L=[]
for j in range(N):
if i!=j:
L.append(j)
for j in range(N-1):
for k in range(K):
if j==0:
if k==a[L[j]] or k==0:
res[j][k]=1
else:
res[j][k]=0
continue
if res[j-1][k]==1:
if k+a[L[j]]<K:
res[j][k+a[L[j]]]=1
res[j][k]=1
return res
def check(i):
table=dp(i)[N-2]
for j in range(max(K-a[i],0),K):
if table[j]==1:
return False
return True
X=sorted([(a[i],i) for i in range(N)])
low=0
high=N
mid=(low+high)//2
if check(X[N-1][1]):
print(N)
exit()
if not(check(X[0][1])):
print(0)
exit()
while((high-low)>1):
mid=(low+high)//2
#range(low,mid) or range(mid,high)
flag=check(X[mid][1])
if flag:
low=mid
else:
high=mid
print(low+1)
|
s057620758 | p03780 | u920299620 | 1543239399 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 1458 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define n_max 5005
int A[n_max];
int n,k;
bool judge( int ind){
int dp[5000]={};
if(A[ind] >=k) return true;
dp[0]=1;
REP(i,n){
int a= A[i];
if(i==ind) continue;
REPR(j,k){
if( j-a >= 0 and dp[j-a] ==1 ) dp[j]=1;
}
}
FOR(i,k-A[ind],k) if(dp[i] == 1) return true;
return false;
}
int main(){
cin >> n >> k;
REP(i,n) cin >> A[i];
sort(A,A+n);
int left = -1;
int right = n-1;
int mid;
while(1){
if(left + 1 >= right ) break;
mid=(left + right) / 2;
if(judge(mid)){
right= mid-1 ;
}
else left = mid;
}
if(judge(right)){
cout << left + 1 << endl;
}
else cout << right +1 << endl;
} |
s983988441 | p03780 | u170201762 | 1540874638 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 512 | N,K = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if a[0] >= K:
print(0)
exit()
a = [a[i] for i in range(N) if a[i]<K]
a.reverse()
N = len(a)
ans = N
dp = [False]*K
dp[0] = True
Smax = 0
for i in range(N):
a_ = a[i]
if Smax + a_ >= K:
ans = N-i-1
updated = False
for j in range(min(Smax,K-a_-1),-1,-1):
if dp[j]:
dp[j+a_=True
if not updated:
Smax = max(Smax,j+a_)
updated = True
print(ans) |
s390657044 | p03780 | u170201762 | 1540858670 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3572 | 268 | N,K = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
for i in range(N):
i = N-i-1
for j in range(K):
if j < a[i]:
dp[i][j] = dp[i+1][j]
else:
dp[i][j] = max(dp[i+1][j],dp[i+1][j-a[i]]+a[i])
print(0) |
s170050503 | p03780 | u170201762 | 1540857395 | Python | Python (3.4.3) | py | Runtime Error | 159 | 12620 | 399 | N,K = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
import numpy as np
b = np.cumsum(np.array(a))
if b[-1] < K:
print(N)
exit()
elif b[0] >= K:
print(0)
exit()
import bisect
i = bisect.bisect(b,K)
w = K-a[i]
b = b[:i]
while b[-1] >= w:
i = bisect.bisect(b,w)
w -= a[i]
if w <= 0:
break
b = b[:i]
if len(b)==0:
break
print(i) |
s972804523 | p03780 | u170201762 | 1540854631 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3572 | 277 | N,K = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
w = 0
for i in range(N):
w += a[i]
if w >= K:
break
if w < K:
print(N)
else:
a = a[:i+1]
for j in range(i):
w -= a[j]
if w < K:
break
print(j) |
s972202666 | p03780 | u201234972 | 1538797774 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3572 | 212 | N, K = map( int, input().split())
A = list( map( int, input().split()))
RA = A.sort( reverse = True)
s = 0
ans = 0
for a in RA:
if s+a < K:
s += A
ans += 1
else:
ans = 0
print(ans) |
s232147521 | p03780 | u608088992 | 1538666948 | Python | Python (3.4.3) | py | Runtime Error | 2107 | 125472 | 764 | import copy
N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
A.sort()
Inf = 5001
def DP(i, K, L, memo = {}):
if i == 0:
return (True if K == 0 else False)
try:
return memo[(i, K)]
except KeyError:
if DP(i-1, K-L[i-1], L, memo) or DP(i-1, K, L, memo):
ret = True
else:
ret = False
memo[(i, K)] = ret
return ret
low, high = 0, N+1
while high - low > 1:
L = copy.deepcopy(A)
mid = (high + low)//2
l = L.pop(mid-1)
if l >= K:
high = mid
else:
memo = {}
for i in range(1, l + 1):
if DP(N-1, K-i, L, memo):
high = mid
break
else:
low = mid
print(low) |
s478637289 | p03780 | u608088992 | 1538665207 | Python | Python (3.4.3) | py | Runtime Error | 2107 | 126996 | 719 | import copy
N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
A.sort()
Inf = 5001
def DP(i, K, L, memo = {}):
if i == 0 and K == 0:
return True
elif i == 0:
return False
try:
return memo[(i, K)]
except KeyError:
if DP(i-1, K-L[i-1], L, memo) or DP(i-1, K, L, memo):
ret = True
else:
ret = False
memo[(i, K)] = ret
return ret
low, high = 0, N+1
while high - low > 1:
L = copy.deepcopy(A)
mid = (high + low)//2
del L[mid-1]
memo = {}
for i in range(1, A[mid-1] + 1):
if DP(N-1, K-i, L, memo):
high = mid
break
else:
low = mid
print(low) |
s160965494 | p03780 | u631277801 | 1536317951 | Python | PyPy3 (2.4.0) | py | Runtime Error | 177 | 38640 | 1022 | # 入力
file = open("g080D.txt", "r")
stdin = file
import sys
stdin = sys.stdin
def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())
from collections import Counter
n,k = li()
a = li()
a_ltk = [ai for ai in a if ai < k]
a_ltk.sort(reverse=True)
need = {ai:False for ai in a_ltk}
# 貪欲に足していく
for i in range(len(a_ltk)):
cur = 0
stack = []
for j in range(i,len(a_ltk)):
cur += a_ltk[j]
stack.append(a_ltk[j])
if cur >= k:
for key in stack:
need[key] = True
stack.pop()
cur -= a_ltk[j]
cnt = Counter(a_ltk)
ans = 0
for k,v in need.items():
if not v:
ans += cnt[k]
print(ans) |
s885956098 | p03780 | u334712262 | 1535507677 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2107 | 71020 | 3305 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
import queue
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
def Prim(g):
V = list(g.keys())
for v in g.values():
V.extend(list(v.keys()))
V = list(set(V))
used = set([])
q = []
heapq.heappush(q, (0, V[0]))
ret = 0
while q:
c, v = heapq.heappop(q)
if v in used:
continue
used.add(v)
ret += c
for u in g[v]:
heapq.heappush(q, (g[v][u], u))
return ret
@mt
def slv2(N, K, A):
@lru_cache(maxsize=None)
def f(w):
if K - A[w] < 0:
return True
dp = [0] * (K)
for i, a in enumerate(A):
if i == w:
continue
tdp = dp[:]
for j in range(K):
if dp[j] and j + a < K:
tdp[j+a] = 1
if a < K:
tdp[a] = 1
dp = tdp
if sum(dp[K-A[w]:]) > 0:
return True
return False
ans = 0
for i in range(N):
if not f(i):
ans += 1
return ans
@mt
def slv(N, K, A):
@lru_cache(maxsize=None)
def f(w):
if K - A[w] <= 0:
return True
dp = [0] * (K)
tdp = [0] * (K)
for i, a in enumerate(A):
if i == w:
continue
tdp[i] = dp[i]
for j in range(K):
if dp[j] and j + a < K:
tdp[j+a] = 1
if a < K:
tdp[a] = 1
dp, tdp = tdp, dp
if sum(dp[K-A[w]:]) > 0:
return True
return False
A.sort()
l = 0
r = N-1
x = 0
while r-l > 1:
# error_print(x)
# x += 1
c = (l+r)//2
if f(c):
r = c
else:
l = c
if f(l):
return l
return r + 1 if not f(r) else l + 1
def main():
N, K = read_int_n()
A = read_int_n()
print(slv(N, K, A))
# for i in range(10000):
# N = random.randint(1, 50)
# K = random.randint(1, 50)
# A = [random.randint(1, 10) for _ in range(N)]
# x = slv(N, K, A[:])
# y = slv2(N, K, A[:])
# print(x, y)
# if x != y:
# print(N, K)
# print(' '.join(map(str, A)))
# return
if __name__ == '__main__':
main()
|
s112941507 | p03780 | u329709276 | 1529138218 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3572 | 203 | N,K = map(int,input().split())
a = sorted(map(int,input().split()))
count = N
s = 0
for i in range(N-1,-1,-1):
if s + N[i] < K:
s += N[i]
else:
count = min(i,count)
print(count)
|
s090247063 | p03780 | u329709276 | 1529137015 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2130 | 425736 | 1170 | N,K = map(int,input().split())
a = list(map(int,input().split()))
dp1 = [[False]*K for _ in range(N)]
dp2 = [[False]*K for _ in range(N)]
# dp[x][y] x枚目まで使った時にyに出来るか
# K-ai <= ai < K となる部分集合を探す
dp1[0][a[0]] = True
dp1[0][0] = True
for i in range(1,N):
for j in range(K):
dp1[i][j] = dp1[i-1][j] or (j-a[i] >= 0 and dp1[i-1][j-a[i]])
dp2[0][a[N-1]] = True
dp2[0][0] = True
for i in range(1,N):
for j in range(K):
dp2[i][j] = dp2[i-1][j] or (j-a[N-i-1] >= 0 and dp2[i-1][j-a[N-i-1]])
count = 0
for i in range(N):
if K-a[i] <= 0:
count += 1
continue
for j in range(K-a[i],K):
f = False
if i == 0:
if dp2[N-2][j]:
count += 1
break
else:
continue
elif i == N-1:
if dp1[N-2][j]:
count += 1
break
else:
continue
for k in range(j+1):
if dp1[i-1][k] and dp2[N-i-2][j-k]:
count += 1
f = True
break
if f:
break
print(N-count)
|
s067688091 | p03780 | u329709276 | 1529109928 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3572 | 360 | N,K = map(int,input().split())
a = list(map(int,input().split()))
a_sum = sum(a)
if a_sum < K:
print(N)
exit()
if a_sum == K:
print(0)
exit()
count = 0
L = [i for i in a if i < K]
L_sum = sum(L)
if L_sum < K:
print(len(K))
exit()
if L_sum == K:
print(0)
exit()
for i in L:
if L_sum - i >= K:
count += 1
print(count)
|
s807408039 | p03780 | u329709276 | 1529109624 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3572 | 360 | N,K = map(int,input().split())
a = list(map(int,input().split()))
a_sum = sum(a)
if a_sum < K:
print(N)
exit()
if a_sum == K:
print(0)
exit()
count = 0
L = [i for i in a if i < K]
L_sum = sum(L)
if L_sum < K:
print(len(N))
exit()
if a_sum == K:
print(0)
exit()
for i in L:
if L_sum - i >= K:
count += 1
print(count)
|
s691120126 | p03780 | u391475811 | 1523307213 | Python | Python (3.4.3) | py | Runtime Error | 2114 | 1097360 | 407 | import bisect
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A.sort()
def solve(a,K):
if A[a]>=K:
return False
bits=1
for i in range(len(A)):
if i!=a:
bits|= bits<<A[i]
cnt = (1<<A[a])-1
bits >>= (K-A[a])
if bits&cnt:
return False
else:
return True
for i in range(N-1,-1,-1):
if solve(i,K):
ans=bisect.bisect_right(A, A[i])
break
print(ans) |
s664673152 | p03780 | u425351967 | 1507654774 | Python | Python (3.4.3) | py | Runtime Error | 2117 | 199284 | 480 | N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
A.sort()
res = []
for n_ex in range(N):
dp = [[False] * K for n in range(N+1)]
dp[0][0] = True
for n in range(N):
for k in range(0, K):
dp[n+1][k] = dp[n][k]
if n != n_ex:
for k in range(0, K - A[n]):
if dp[n][k] == True:
dp[n+1][k+A[n]] = True
for k in range(K-A[n_ex], K):
if dp[N][k] == True:
res.append(n_ex)
break
print(N-len(res)) |
s696254298 | p03780 | u425351967 | 1507652970 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2135 | 439816 | 480 | N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
A.sort()
res = []
for n_ex in range(N):
dp = [[False] * K for n in range(N+1)]
dp[0][0] = True
for n in range(N):
for k in range(0, K):
dp[n+1][k] = dp[n][k]
if n != n_ex:
for k in range(0, K - A[n]):
if dp[n][k] == True:
dp[n+1][k+A[n]] = True
for k in range(K-A[n_ex], K):
if dp[N][k] == True:
res.append(n_ex)
break
print(N-len(res)) |
s929659765 | p03780 | u425351967 | 1507652963 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 201076 | 480 | N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
A.sort()
res = []
for n_ex in range(N):
dp = [[False] * K for n in range(N+1)]
dp[0][0] = True
for n in range(N):
for k in range(0, K):
dp[n+1][k] = dp[n][k]
if n != n_ex:
for k in range(0, K - A[n]):
if dp[n][k] == True:
dp[n+1][k+A[n]] = True
for k in range(K-A[n_ex], K):
if dp[N][k] == True:
res.append(n_ex)
break
print(N-len(res)) |
s724833913 | p03780 | u425351967 | 1507647504 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 201076 | 522 | N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
A.sort()
res = []
for n_ex in range(N):
A_tmp = A.copy()
A_tmp.pop(n_ex)
dp = [[False] * K for n in range(N)]
dp[0][0] = True
for cnt in range(1, N):
for k in range(0, K):
dp[cnt][k] = dp[cnt-1][k]
for k in range(0, K - A_tmp[cnt-1]):
if dp[cnt-1][k] == True:
dp[cnt][k+A_tmp[cnt-1]] = True
for k in range(K-A[n_ex], K):
if dp[N-1][k] == True:
res.append(n_ex)
break
print(N-len(res)) |
s419006732 | p03780 | u619384481 | 1504841009 | Python | Python (2.7.6) | py | Runtime Error | 1145 | 3032 | 849 | ini=map(int,raw_input().split())
a=map(int,raw_input().split())
b=[]
for i in a:
b.append(i)
b.sort()
c=[]
while True:
sum=0
add=0
for i in b:
sum+=i
if sum<ini[1] and len(c)>=1:
b.append(c[-1])
c.pop(-1)
c.reverse()
while True:
sum=0
for i in c:
sum+=i
if sum<ini[1]:
break
time=0
sum=0
for i in c:
sum+=i
time+=1
if sum>=ini[1]:
add+=time
for j in range(time):
c.pop(j)
sum=0
time=0
break
elif sum<ini[1] and len(c)==0:
b=c
break
else:
c.append(b[0])
b.pop(0)
print ini[0]-len(b)-add |
s017907565 | p03780 | u063962277 | 1497157758 | Python | Python (3.4.3) | py | Runtime Error | 2120 | 263688 | 473 | N, K = map(int, input().split())
a = [int(i) for i in input().split()]
ok = []
for i in range(N):
b = a.copy()
del b[i]
dp = [[0 for y in range(K)] for x in range(N-1)]
for x in range(N-1):
if b[x] < K:
dp[x][b[x]] = 1
for y in range(K):
dp[x][y] += dp[x-1][y]
if y > b[x]:
dp[x][y] += dp[x-1][y-b[x]]
if sum(dp[N-2][K-a[i]:K])>0:
ok.append(a[i])
ans = N - len(ok)
print(ans) |
s866803227 | p03780 | u683479402 | 1494365275 | Python | Python (3.4.3) | py | Runtime Error | 2121 | 275060 | 661 | #ABC56 D #1245870
N,K = map(int, input().split())
A = sorted(list(map(int, input().split())))
l = 0
r = N
while(r > l):
s = int((l+r)/2)
if A[s] > K:
r = s
continue
si = False
dp = [[False for i in range(K+2)] for j in range(K+2)]
dp[0][0] = True
for i in range(1,N):
for j in range(K):
if(dp[i-1][j] == True):
dp[i][j] = True
if i != s and j >= A[i] and dp[i-1][j-A[i]]:
dp[i][j] = True
for i in range(K-A[s], K):
if dp[N-1][i]:
si = True
break
if(si == True):
r = s
else:
l = s+1
print(r) |
s170010213 | p03780 | u683479402 | 1494332060 | Python | Python (3.4.3) | py | Runtime Error | 2117 | 213876 | 671 | #ABC56 D input
nk = list(map(int, input().split()))
N = nk[0]
K = nk[1]
A = sorted(list(map(int, input().split())))
count = 0
for a in A:
new_a = A[:]
new_a.remove(a)
dp = [[-1 for i in range(N)] for j in range(K+1)]
for i in range(N):
dp[0][i] = True
for i in range(1,K+1):
dp[i][0] = False
for i in range(1,K+1):
for j in range(1, N):
dp[i][j] = dp[i][j-1]
if(i >= new_a[j-1]):
dp[i][j] = dp[i][j] or dp[i-new_a[j-1]][j-1]
res = False
for i in range(K-a,K):
res = res or dp[i][N-1]
if(res == False):
count += 1
print(count) |
s421000923 | p03780 | u580316060 | 1491318763 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 39328 | 1043 | def whatIsMinNumber(X_copy,K):
pickupNum = X_copy[len(X_copy)//2]
X_rest = X[:]
X_rest.remove(pickupNum)
if can_do_number(X_rest,0,K-pickupNum,K-1):
if len(X_copy) > 2:
return whatIsMinNumber(X_copy[len(X_copy)//2+1:len(X_copy)],K)
else:
return pickupNum
else:
if len(X_copy) > 1:
return whatIsMinNumber(X_copy[0:len(X_copy)//2],K)
else:
return pickupNum+1
def can_do_number(X,sum,min,max):
if len(X) == 0:
return False
for i in range(0,len(X)):
if min <= sum <= max:
return True
elif min <= sum+X[i] <= max:
return True
elif min > sum+X[i]:
X_rest = X[:]
sum = sum + X_rest.pop(i)
can_do_number(X_rest,sum,min,max)
else:
pass
return False
N,K = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort(reverse = True)
thenum = whatIsMinNumber(X[:],K)
print(len(list(filter((lambda x:x<thenum),X)))) |
s945310354 | p03780 | u580316060 | 1491317398 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 39328 | 987 | def whatIsMinNumber(X_copy,K):
pickupNum = X_copy[len(X_copy)//2]
X_rest = X[:]
X_rest.remove(pickupNum)
if can_do_number(X_rest,0,K-pickupNum,K-1):
if len(X_copy) > 2:
return whatIsMinNumber(X_copy[len(X_copy)//2+1:len(X_copy)],K)
else:
return pickupNum
else:
if len(X_copy) > 1:
return whatIsMinNumber(X_copy[0:len(X_copy)//2],K)
else:
return pickupNum+1
def can_do_number(X,sum,min,max):
if len(X) == 0:
return False
for i in range(0,len(X)):
if min <= sum+X[i] <= max:
return True
elif min > sum+X[i]:
X_rest = X[:]
sum = sum + X_rest.pop(i)
can_do_number(X_rest,sum,min,max)
else:
pass
return False
N,K = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort(reverse = True)
thenum = whatIsMinNumber(X[:],K)
print(len(list(filter((lambda x:x<thenum),X)))) |
s657698371 | p03780 | u580316060 | 1491313234 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 39344 | 1096 | def whatIsMinNumber(X_copy,K):
pickupNum = X_copy[len(X_copy)//2]
X_rest = X[:]
X_rest.remove(pickupNum)
if can_do_number(X_rest,pickupNum,K,K+pickupNum-1):
if len(X_copy) > 2:
return whatIsMinNumber(X_copy[len(X_copy)//2+1:len(X_copy)],K)
else:
return pickupNum
else:
if len(X_copy) > 1:
return whatIsMinNumber(X_copy[0:len(X_copy)//2],K)
else:
return pickupNum+1
def can_do_number(X,sum,min,max):
#残りのカードがない場合はFalseを返す
if len(X) == 0:
return False
#残りのカードで順番に調べる
for i in range(0,len(X)):
if min <= sum+X[i] <= max:
return True
elif min > sum+X[i]:
X_rest = X[:]
sum = sum + X_rest.pop(i)
can_do_number(X_rest,sum,min,max)
else:
pass
return False
N,K = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort(reverse = True)
thenum = whatIsMinNumber(X[:],K)
print(len(list(filter((lambda x:x<thenum),X)))) |
s782855056 | p03780 | u209647862 | 1490921086 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3700 | 764 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import array
n, k = map(int, input().split())
cards = list(map(int, input().split()))
needs = 0
for i, val in enumerate(cards):
if val >= k:
needs += 1
continue
c_without_i = cards[:i] + cards[i + 1:]
dp = array.array('b', [0] * k)
dp2 = array.array('b', [0] * k)
b = False
for m in c_without_i:
if m >= k: continue
for j, v in enumerate(dp):
dp2[i] = v
if v is 1 and (j + m) < k:
if k - val <= j + m:
needs += 1
b = True
break
dp2[j + m] = 1
if b:
break
dp2[m] = 1
dp, dp2 = dp2, dp
print(n - needs)
|
s892532253 | p03780 | u040380068 | 1490509255 | Python | Python (2.7.6) | py | Runtime Error | 13 | 2948 | 499 | def calc(lst, k):
sum = 0
i = 0
while sum < k and i < len(inptsort):
sum += lst[i]
i += 1
if sum < k:
return i
else:
df = sum - k
sum2 = 0
j = 0
while sum2 < df and j < i:
sum2 += lst[j]
j += 1
if lst[j-1] != lst[j]:
return j
else:
j -= 1
while j >= 1:
if lst[j-1] != lst[j]:
return j
j -= 1
return 0
inpt1 = map(int, raw_input().split())
inpt2 = map(int, raw_input().split())
inptsort = sorted(inpt2)
print calc(inptsort, inpt1[1]) |
s296013610 | p03780 | u982653403 | 1490305279 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 4140 | 560 | n, k = map(int, input().split())
a = sorted(filter(lambda x: x < k, map(int, input().split())))
def check(start, end, l):
s = set()
s.add(0)
for i in l:
for x in s.copy():
if start <= i + x and i + x < end:
return True
if i + x < start:
s.add(i + x)
return False
p1 = 0
p2 = len(a)
res = None
while p1 < p2:
i = (p1 + p2) // 2
b = a.copy()
b.pop(i)
res = check(k - a[i], k, b)
if res:
p2 = i
else:
p1 = i + 1
print(i if res else i + 1)
|
s382689856 | p03780 | u982653403 | 1490305051 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 4140 | 577 | #### TLE ####
n, k = map(int, input().split())
a = sorted((filter(lambda x: x < k, map(int, input().split()))))
def check(start, end, l):
s = set()
s.add(0)
for i in l:
for x in s.copy():
if start <= i + x and i + x < end:
return True
if i + x < start:
s.add(i + x)
return False
p1 = 0
p2 = len(a)
res = None
while p1 < p2:
i = (p1 + p2) // 2
b = a.copy()
b.pop(i)
res = check(k - a[i], k, b)
if res:
p2 = i
else:
p1 = i + 1
print(i if res else i + 1)
|
s980173126 | p03780 | u908424816 | 1490130071 | Python | Python (2.7.6) | py | Runtime Error | 281 | 2948 | 416 |
def main():
N, K = map(int, raw_input().split())
cards = map(int, raw_input().split())
c = []
while sum(c) <= K:
c.append(cards.pop(cards.index(min(cards))))
if len(cards) == 0 and sum(c) < K:
print len(c)
return 0
count = 0
while sum(c) >= K:
c.pop(c.index(min(c)))
count += 1
print count-1
if __name__ == '__main__':
main() |
s085971508 | p03780 | u795179699 | 1489978994 | Python | Python (3.4.3) | py | Runtime Error | 2130 | 411380 | 1364 | #!/usr/local/bin/python3
import bisect
(n, k) = tuple(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
a = sorted(a)
l = bisect.bisect_left(a, k)
a = a[0:l]
minsum = k - a[-1]
stf = [[False for j in range(k)] for i in range(l)]
stb = [[False for j in range(k)] for i in range(l)]
stf[0][a[0]] = True
stf[0][0] = True
for i in range(1, l):
for x in range(k):
if x - a[i] >= 0:
stf[i][x] = stf[i - 1][x] | stf[i - 1][x - a[i]]
else:
stf[i][x] = stf[i - 1][x]
stb[l - 1][a[l - 1]] = True
stb[l - 1][0] = True
for i in range(l - 2, -1, -1):
for x in range(k):
if x - a[i] >= 0:
stf[i][x] = stf[i + 1][x] | stf[i + 1][x - a[i]]
else:
stf[i][x] = stf[i + 1][x]
cc = 0
for i in range(l):
found = False
for x in range(k - a[i], k):
if i == 0:
if stb[1][x] == True:
found = True
break
elif i == l - 1:
if stf[l - 2][x] == True:
found = True
break
else:
for y in range(x + 1):
if stf[i - 1][y] == True and stb[i + 1][x - y] == True:
found = True
break
if found:
break
if found:
break
else:
cc += 1
print(cc)
|
s042729492 | p03780 | u795179699 | 1489952949 | Python | Python (3.4.3) | py | Runtime Error | 2105 | 17216 | 2076 | #!/usr/local/bin/python3
import bisect
(n, k) = tuple(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
a = sorted(a)
i = bisect.bisect_left(a, k)
a = a[0:i]
ct = {}
ad = []
prevnum = 0
cc = 1
for i in a:
if prevnum != i:
ct[prevnum] = cc
ad.append(i)
prevnum = i
cc = 1
else:
cc += 1
else:
ct[prevnum] = cc
a = ad
#print(a)
#print(ct)
def getSumComb(a, idx, cur, sl, minsum, maxsum):
pairs = []
num = a[idx]
c = ct[num]
for i in range(0, c + 1):
if cur + num * i < minsum:
slc = sl[:]
for j in range(i):
slc.append(num)
if idx + 1 < len(a):
pairs.extend(getSumComb(a,
idx + 1,
cur + num * i,
slc,
minsum,
maxsum))
elif minsum <= cur + num * i < maxsum:
slc = sl[:]
for j in range(i):
slc.append(num)
slcc = slc[:]
if i > 0:
pairs.append((cur + num * i, slc))
if idx + 1 < len(a):
pairs.extend(getSumComb(a,
idx + 1,
cur + num * i,
slcc,
minsum,
maxsum))
elif maxsum <= cur + num * i:
break
return pairs
if len(a) > 0:
pairs = getSumComb(a, 0, 0, [], k - a[-1], k)
else:
pairs = []
pairs = sorted(pairs)
#print(pairs)
nn = 0
for num in a:
minsum = k - num
p = (minsum, [])
idx = bisect.bisect_left(pairs, p)
found = False
for i in range(idx, len(pairs)):
if pairs[i][1].count(num) < ct[num]:
found = True
break
if not found:
nn += ct[num]
print(nn)
|
s083171665 | p03780 | u795179699 | 1489952581 | Python | Python (3.4.3) | py | Runtime Error | 2105 | 17856 | 2031 | #!/usr/local/bin/python3
import bisect
(n, k) = tuple(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
a = sorted(a)
i = bisect.bisect_left(a, k)
a = a[0:i]
ct = {}
ad = []
prevnum = 0
cc = 1
for i in a:
if prevnum != i:
ct[prevnum] = cc
ad.append(i)
prevnum = i
cc = 1
else:
cc += 1
else:
ct[prevnum] = cc
a = ad
#print(a)
#print(ct)
def getSumComb(a, idx, cur, sl, minsum, maxsum):
pairs = []
num = a[idx]
c = ct[num]
for i in range(0, c + 1):
if cur + num * i < minsum:
slc = sl[:]
for j in range(i):
slc.append(num)
if idx + 1 < len(a):
pairs.extend(getSumComb(a,
idx + 1,
cur + num * i,
slc,
minsum,
maxsum))
elif minsum <= cur + num * i < maxsum:
slc = sl[:]
for j in range(i):
slc.append(num)
slcc = slc[:]
if i > 0:
pairs.append((cur + num * i, slc))
if idx + 1 < len(a):
pairs.extend(getSumComb(a,
idx + 1,
cur + num * i,
slcc,
minsum,
maxsum))
elif maxsum <= cur + num * i:
break
return pairs
pairs = getSumComb(a, 0, 0, [], k - a[-1], k)
pairs = sorted(pairs)
#print(pairs)
nn = 0
for num in a:
minsum = k - num
p = (minsum, [])
idx = bisect.bisect_left(pairs, p)
found = False
for i in range(idx, len(pairs)):
if pairs[i][1].count(num) < ct[num]:
found = True
break
if not found:
nn += ct[num]
print(nn)
|
s019737048 | p03780 | u608297208 | 1489940523 | Python | PyPy3 (2.4.0) | py | Runtime Error | 173 | 38384 | 740 | import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
need = []
iranaiko = []
for a in A:
if a >= K:
need.append(a)
elif a in need:
need.append(a)
elif a in iranaiko:
pass
else:
z = 0
B = A[:]
B.remove(a)
fusoku = [K - i - 1 for i in range(a)]
for bi,b in enumerate(B):
if b >= K:
break
B = B[:bi + 1]
for i in range(1,len(B) + 1):
C = list(itertools.combinations(B,i))
for c in C:
if sum(c) in fusoku:
need.append(a)
z = 1
break
if z == 1:
break
if z == 0:
iranaiko.append(a)
print(N - len(need)) |
s323041396 | p03780 | u314057689 | 1489891160 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3572 | 688 | def main():
global K,N,A,AM
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
flag = (max(A) >= K) # よい部分集合がないということはない
AM = sum(A)
if not flag and AM < K: # よい集合が存在しない
print(len(A))
return
print(binary_search_for_integer(len(A)-1, -1)-1)
def binary_search_for_integer(ok, ng):
while math.fabs(ok-ng) > 1:
mid = (ok+ng)/2
if solve(mid):
ok = mid
else:
ng = mid
return ok
def solve(x):
if AM - x >= K:
return False
else:
return True
if __name__ == "__main__":
main()
|
s004933751 | p03780 | u204637741 | 1489890933 | Python | Python (3.4.3) | py | Runtime Error | 223 | 3572 | 260 | a, b=map(int,input().split())
s=list(map(int,input().split()))
k=1
if(sum(s)<b):
print(a)
k=2
s.sort()
ss=list(filter(lambda x: x < b, s))
i=int(0)
while(k==1):
del ss[0]
if(sum(ss)==b):
i=i+1
print(i)
k=2
elif(sum(ss)<=b):
print(i)
k=2
i=i+1
|
s317574875 | p03780 | u787988531 | 1489890853 | Python | Python (2.7.6) | py | Runtime Error | 11 | 3076 | 121 | K = int(raw_input().split(" ")[1])
d = map(int, raw_input())
s = sum(d)
c = 0
for i in d:
if s - i > K:
c += 1
print c |
s171427437 | p03780 | u204637741 | 1489890832 | Python | Python (3.4.3) | py | Runtime Error | 235 | 3572 | 259 | a, b=map(int,input().split())
s=list(map(int,input().split()))
s.sort()
if(sum(s)<b):
print(a)
k=2
ss=list(filter(lambda x: x < b, s))
i=int(0)
k=1
while(k==1):
del ss[0]
if(sum(ss)==b):
i=i+1
print(i)
k=2
elif(sum(ss)<=b):
print(i)
k=2
i=i+1
|
s712403321 | p03780 | u204637741 | 1489890811 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3572 | 260 | a, b=map(int,input().split())
s=list(map(int,input().split()))
s.sort()
if(sum(ss)<b):
print(a)
k=2
ss=list(filter(lambda x: x < b, s))
i=int(0)
k=1
while(k==1):
del ss[0]
if(sum(ss)==b):
i=i+1
print(i)
k=2
elif(sum(ss)<=b):
print(i)
k=2
i=i+1
|
s230862285 | p03780 | u723654028 | 1489890491 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 4520 | 441 | def calcsum(a, K, i, d=0, s=0):
if K - a[i] <= s < K:
return True
elif i == d:
return calcsum(a, K, i, d+1, s)
elif d == len(a):
return False
else:
return calcsum(a, K, i, d+1, s) | calcsum(a, K, i, d+1, s+a[d])
N, K = map(int, input().split())
a = list(map(int, input().split()))
a_sum = sum(a)
count = 0
for i in range(N):
count += calcsum(a, K, i)
count = N - count
print(count)
|
s360601217 | p03780 | u743272507 | 1489889527 | Python | Python (3.4.3) | py | Runtime Error | 3521 | 19956 | 690 | n,k = map(int,input().split())
a = list(map(int, input().split()))
sm = sum(a)
if k>sm: print(n)
else:
table = [[0] for i in range(2*k)]
table[0] = [-1]
for elm in a:
idxlist = []
for i in range(2*k):
if table[i] != [0]:
if i+elm<2*k:
idxlist.append(i+elm)
for idx in idxlist:
table[idx].extend(table[idx-elm])
table[idx].append(elm)
need = 0
for elm in a:
if elm >= k: need += 1
else:
flag = False
for i in range(k,k+elm):
if elm in table[i]:
need += 1
break
print(n-need) |
s540749317 | p03781 | u344122377 | 1591321254 | Python | Python (3.4.3) | py | Runtime Error | 76 | 4236 | 202 | import math
n = int(input());
dp = []
def dfs(x, i) :
dp[i] = dp[i-1] + i
if dp[i] >= n :
return i
return dfs(dp[i], i+1)
sz = int(math.sqrt(n)) + 10
dp = [0] * sz
ans = dfs(0, 1)
print(ans) |
s802034625 | p03781 | u813174766 | 1582770869 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 69 | n=int(input())
i=int(sqrt(n))//2
while(i*(i+1)//2<n):
i+=1
print(i) |
s014285065 | p03781 | u273010357 | 1582173911 | Python | Python (3.4.3) | py | Runtime Error | 158 | 12496 | 282 | import itertools
import numpy as np
X = int(input())
L = list(range(X))
L = list(itertools.accumulate(L))
def getNearestValue(list, num):
idx = np.abs(np.asarray(list) - num).argmin()
return list[idx]
tmp = getNearestValue(L, X)
tmp1 = abs(X-tmp)
print(L.index(tmp)+tmp1) |
s850896058 | p03781 | u941407962 | 1581049324 | Python | PyPy3 (2.4.0) | py | Runtime Error | 167 | 38384 | 728 | N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
dp2 = [1] + [0]*K
dpm = [[0]*(K+1) for _ in range(N+1)]
dpm[0][0] = 1
for i, a in enumerate(A):
for j in range(K, -1, -1):
dpm[i+1][j] = dpm[i][max(0, j-a)] + dpm[i][j]
#print(dpm)
r = 0
for i, a in enumerate(A[::-1]):
f = True
for j in range(K, -1, -1):
# 後ろiこの合計がjのもの
if f and dp2[j] > 0:
# K-j > x >= K-j-a
if dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
f = False
if j-a>=0:
dp2[j] = dp2[j] + dp2[j-a]
if f:
r += 1
# for j in range(K-1, 0, -1):
# print("aa", i, N-i-1)
print(r)
|
s825745364 | p03781 | u691896522 | 1575573271 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3060 | 212 | import itertools
import bisect
x = int(input())
acc = list(itertools.accumulate(list(range(1, x+1))))
index = bisect.bisect_left(acc, x)
#print(acc)
if acc[index] == x:
print(index+1)
else:
print(index+1) |
s672999882 | p03781 | u152452056 | 1575329279 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1198 | #include <bits/stdc++.h>
using namespace std;
// 287644PV
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(6)<<(x)
const long long mod = 1000000007;
void addSelf(long long&x, long long y)
{
x+= y;
if(x >= mod)
x-=mod;
}
void subSelf(long long&x, long long y)
{
x -= y;
if(x < 0)
x += mod;
}
long long gcd(long long a, long long b)
{
if(b == 0)
return a;
else
return gcd(b,a%b);
}
long long power(long long base, long long expo)
{
long long sol = 1;
for (long long i = 0; i <expo ; ++i) {
sol *= base;
}
return sol;
}
bool compare1(pair<long long,long long> i,pair<long long,long long> j) // 1 < i < n
{
return i.second < j.second;
}
bool compare2(pair<long long,long long> i, pair<long long,long long> j) //n > n-i > 1
{
return i.first > j.first;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x;
cin >> x;
int lower = sqrt((double) 2*x+0.25)-0.5;
lower--;
int curr = (lower*(lower+1))/2;
int i = 1;
while(true)
{
if(curr + i == x)
{
cout << i;
break;
}
i++;
}
return 0;
} |
s549661249 | p03781 | u109617108 | 1574815783 | Python | PyPy3 (2.4.0) | py | Runtime Error | 162 | 38256 | 69 | X=int(input())
i=1
sum1=1
while sum<X:
i+=1
sum1=sum1+i
print(i)
|
s187884056 | p03781 | u109617108 | 1574815051 | Python | PyPy3 (2.4.0) | py | Runtime Error | 166 | 38256 | 120 | X=int(input())
import numpy as np
dp=np.array([0]*X)
i=0
while X not in dp:
i+=1
dp+=np(dp+np.array(X*[i]))
print(i) |
s934774456 | p03781 | u292746386 | 1574812512 | Python | Python (2.7.6) | py | Runtime Error | 256 | 16520 | 646 | import numpy as np
N, K = map(int, raw_input().split())
A = np.array(map(int, raw_input().split()))
A = np.sort(A)
Sum = A.sum()
if Sum < K:
print N
else:
# Find the Smallest Necessary Number
# SmallNec = N-1
A_cumsum = np.concatenate(([0], np.cumsum(A)))
# SubSet A[0:I]
I = np.where(A_cumsum<K)[0][-1] + 1
Sum_ = A_cumsum[I]
while Sum_ >= K:
for J in xrange(I-1, -1, -1):
if A[J] >= Sum_ - K:
# A[J] is Necessary
I = J
pass
else:
# A[J] Maybe Unnecessary
break
Sum_ = A_cumsum[I]
print I |
s497572686 | p03781 | u292746386 | 1574808405 | Python | Python (2.7.6) | py | Runtime Error | 221 | 16264 | 428 | import sys
import numpy as np
N, K = map(int, raw_input().split())
A = np.array(map(int, raw_input().split()))
A = np.sort(A)
Sum = A.sum()
if Sum < K:
print N
sys.exit()
A_cumsum = np.concatenate(([0], np.cumsum(A)))
I = np.where(A_cumsum<K)[0][-1] + 1
Sum_ = A_cumsum[I]
while Sum_ > K:
for J in xrange(I-1, -1, -1):
if A[J] <= Sum_ - K:
break
I = J + 1
Sum_ = A_cumsum[I]
print I |
s087612011 | p03781 | u543954314 | 1571323074 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 603 | def main():
n,k = map(int,input().split())
a = list(filter(lambda x:x<k,list(map(int,input().split()))))
n = len(a)
a.sort(reverse=True)
ng = -1
ok = n
while ok-ng > 1:
mid = (ok+ng)//2
dp = [False]*(k+1)
dp[0] = True
f = 0
for j in range(n):
if j == mid:
continue
w = a[j]
for i in range(k,w-1,-1):
if dp[i-w]:
dp[i] = True
if k-a[mid] <= i < k:
ng = mid
f = 1
break
if f:
break
else:
ok = mid
print(n-ok)
if __name__ == "__main__":
main()
|
s600510772 | p03781 | u463655976 | 1569667813 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 101 | x = int(input())
t = (-1 + math.sqrt(1 + 8 * x))
if t % 2 == 0:
print(t//2)
else:
print(t//2+1)
|
s384522490 | p03781 | u230265105 | 1567035796 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 61 | x = int(input())
i = 0
while x>0
i = i+1
x = x-i
print(i) |
s097337857 | p03781 | u230265105 | 1567035286 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 57 | x = int(input())
i=0
while x>0
i++
x=x-i
print(i)
|
s755550709 | p03781 | u778814286 | 1564261248 | Python | PyPy3 (2.4.0) | py | Runtime Error | 177 | 38640 | 724 | ###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
MOD = 10**9 + 7
sys.setrecursionlimit(10**7)
# 4近傍(右, 下, 左, 上)
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###
N = ii()
print('1' + ''.join(['0'] * (N-1)))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.