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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s575724008 | p03781 | u393512980 | 1563935913 | Python | PyPy3 (2.4.0) | py | Runtime Error | 172 | 38256 | 771 | import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
S, f = [set() for i in range(N+1)], [[0] * K for i in range(N+1)]
S[0].add(0)
f[N][0] = 1
for i, (al, ar) in enumerate(zip(a, a[::-1]), 1):
for j in S[i-1]:
S[i].add(j)
x = al + j
if x < K:
S[i].add(x)
for j in range(K):
if f[-i][j]:
f[-i-1][j] = 1
if ar+j < K:
f[-i-1][ar+j] = 1
for i in range(N):
for j in range(1, K):
f[i][j] += f[i][j-1]
cnt = 0
for i, x in enumerate(a):
if x >= K:
cnt += 1
continue
for j in S[i]:
if K-x-j-1 < 0 or f[i+1][K-j-1]-f[i+1][K-x-j-1] > 0:
cnt += 1
break
print(N - cnt)
|
s681927080 | p03781 | u350997995 | 1554181959 | Python | Python (3.4.3) | py | Runtime Error | 73 | 4076 | 161 | X = int(input())
def dfs(t, x):
global X
if t>X:
return X
if x==X:
return t-1
return min(dfs(t+1,x+t),dfs(t+1,x))
print(dfs(0,0)) |
s096192823 | p03781 | u047535298 | 1542808259 | Python | Python (3.4.3) | py | Runtime Error | 78 | 3984 | 315 | def reduce (last, count, time):
if last == 0:
return time-1
if last-time==0 or last-time > time:
return reduce(last-time, count+1, time+1)
else:
return reduce(last, count, time+1)
if __name__ == '__main__':
X = int(input())
ret = reduce(X, 0, 1)
print(ret)
|
s942857206 | p03781 | u333139319 | 1539110499 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 110 | x = int(input())
for i in range(1,x//2+1):
a = a + i
if a >= x:
print(x//2)
else:
print(x//2+1)
|
s470388725 | p03781 | u284119783 | 1529480073 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 217 | N, K = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ans = N
t = 0
for i in range(N-1, -1, -1) :
if t+a[i] < K :
t += a[i]
else :
ans = min(ans, i)
print(ans) |
s103516080 | p03781 | u777923818 | 1515110957 | Python | PyPy3 (2.4.0) | py | Runtime Error | 186 | 38768 | 686 | # -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from copy import deepcopy
from operator import add
from itertools import accumulate
N, K = inpl()
A = sorted(inpl())
S = list(accumulate(A, add))
A = A[::-1]
DP = [False for _ in range(K)]
DP[0] = 1
OK = [False for _ in range(N)]
for i, a in enumerate(A):
DP0 = deepcopy(DP)
if a >= K:
OK[i] = True
continue
for j, d in enumerate(DP0[-S[::-1][i]:], max(0, K-S[::-1][i])):
if d:
if j + a >= K:
OK[i] = True
break
else:
DP[j+a] = True
if sum(OK) == 0:
print(N)
else:
print(OK[::-1].index(True)) |
s636271929 | p03781 | u777923818 | 1515109976 | Python | PyPy3 (2.4.0) | py | Runtime Error | 195 | 38768 | 568 | # -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from copy import deepcopy
N, K = inpl()
A = sorted(inpl(), reverse=True)
DP = [False for _ in range(K)]
DP[0] = 1
OK = [False for _ in range(N)]
for i, a in enumerate(A):
DP0 = deepcopy(DP)
if a >= K:
OK[i] = True
continue
for j, d in enumerate(DP0):
if d:
if j + a >= K:
OK[i] = True
break
else:
DP[j+a] = True
if sum(OK) == 0:
print(N)
else:
print(OK[::-1].index(True)) |
s353755267 | p03781 | u985443069 | 1489967381 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 1044 | import sys
sys.stdin = open('d3.in')
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
prefix = [set() for _ in range(n + 1)]
# suffix = [set() for _2 in range(n + 1)]
prefix[0] = {0}
for i in range(n):
for v in prefix[i]:
prefix[i+1].add(v)
if v + a[i] <= k:
prefix[i+1].add(v + a[i])
suffix_i = {0}
# Cumulative sums
c_suffix = [[0] * (k+1) for _3 in range(n + 1)]
for j in range(k):
c_suffix[n][j + 1] = c_suffix[n][j] + (j in suffix_i)
for i in range(n - 1, -1, -1):
to_add = set()
for v in suffix_i:
if v + a[i] <= k:
to_add.add(v + a[i])
suffix_i.update(to_add)
for j in range(k):
c_suffix[i][j + 1] = c_suffix[i][j] + (j in suffix_i)
def find(i):
if k <= a[i]:
return 0
for s in prefix[i]:
start = max(0, k - a[i] - s)
stop = k - s
if c_suffix[i + 1][stop] - c_suffix[i + 1][start] > 0:
return 0
return 1
res = 0
for i in range(n):
res += find(i)
print(res)
|
s185730275 | p03781 | u985443069 | 1489965886 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3316 | 961 | # import sys
# sys.stdin = open('d3.in')
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
prefix = [set() for _ in range(n + 1)]
suffix = [set() for _2 in range(n + 1)]
prefix[0] = {0}
for i in range(n):
for v in prefix[i]:
if v + a[i] <= k:
prefix[i+1].add(v + a[i])
suffix[n] = {0}
for i in range(n - 1, -1, -1):
suffix[i] = set(suffix[i + 1])
for v in suffix[i + 1]:
if v + a[i] <= k:
suffix[i].add(v + a[i])
# Cumulative sums
c_suffix = [[0] * (k+1) for _3 in range(n + 1)]
for i in range(n + 1):
for j in range(k):
c_suffix[i][j + 1] = c_suffix[i][j] + (j in suffix[i])
def find(i):
if k <= a[i]:
return 0
for s in prefix[i]:
start = max(0, k - a[i] - s)
stop = k - s
if c_suffix[i + 1][stop] - c_suffix[i + 1][start] > 0:
return 0
return 1
res = 0
for i in range(n):
res += find(i)
print(res)
|
s880964668 | p03781 | u271456715 | 1489898530 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 994 | import sys
[n, k] = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]
a.sort()
if sum(a) < k:
print(n)
sys.exit()
s = 0
for i in range(len(a)):
s += a[i]
if s >= k:
break
aa = [x for x in a if x < a[i]]
bb = [x for x in a if x < k]
cc = []
for i in range(len(aa)):
c = bb[:i] + bb[i+1:]
t = k - bb[i]
c.reverse()
#print(c)
flg = 0
j = 0
s = 0
f = [0 for x in range(len(c))]
while True:
f[j] = 1
#print(c)
#print(f)
s += c[j]
if s >= t and s < k:
flg = 1
#print(c)
#print(f)
break
if s >= k:
f[j] = 0
s -= c[j]
j += 1
if j == len(c):
ii = -1
for jj in range(len(c) - 1):
if f[jj] == 1:
ii = jj
if ii == -1:
break
else:
for l in range(ii, len(c)):
f[l] = 0
j = ii + 1
s = sum([c[l] * f[l] for l in range(len(c))])
if flg== 0:
cc.append(bb[i])
#print(cc)
print(len(cc))
|
s405407930 | p03781 | u272028993 | 1489891612 | Python | PyPy2 (5.6.0) | py | Runtime Error | 36 | 28140 | 509 | n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
a.sort()
used=[False]*n
idx=n-1
cnt=0
while True:
if idx-cnt<0:
break
tmp=sum(a[idx-cnt:idx+1])
if tmp<k:
cnt+=1
continue
for i in xrange(idx-cnt,idx+1):
used[i]=True
tmp-=a[idx-cnt]
for i in xrange(idx-cnt-1,-1,-1):
if tmp+a[i]>=k:
used[i]=True
else:
break
idx-=1
cnt=0
ans=0
for i in xrange(n):
if not used[i]:
ans+=1
print ans |
s940151159 | p03781 | u140806166 | 1489885773 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 93 | x = input()
d = 0
for i in range(1, 10 ** 6):
d += i
if x <= d:
print(i)
break
|
s149824372 | p03782 | u786020649 | 1595369046 | Python | PyPy3 (7.3.0) | py | Runtime Error | 91 | 74460 | 2669 | import sys
import numpy as np
sys.setrecursionlimit(4100000)
def biser(lst,func):
n=len(lst)
nh=n//2
if n==1:
if func(lst[0]):
return lst[0]
else:
return -1
if func(lst[nh]):
return biser(lst[nh:],func)
else:
return biser(lst[:nh],func)
def findminsum(lst,K,N):
inf=10**6
dp=[[inf]*N for s in range(K+1)]
for s in range(K+1):
for j in range(N):
if j==0 and s<=lst[j]:
dp[s][j]=lst[0]
elif s>lst[j] and j>0:
dp[s][j]=min(dp[s-lst[j]][j-1]+lst[j], dp[s][j-1])
elif s<=lst[j] and j>0:
dp[s][j]=min(lst[j],dp[s][j-1])
# print(lst)
# print(dp[0][:])
# print(dp[1][:])
# print(dp[K][:])
return dp[K][N-1]
dp=[[inf]*N for s in range(K+1)]
for s in range(K+1):
for j in range(N):
if j==0 and s<=lst[j]:
dp[s][j]=lst[0]
elif s>lst[j] and j>0:
dp[s][j]=min(dp[s-lst[j]][j-1]+lst[j], dp[s][j-1])
elif s<=lst[j] and j>0:
dp[s][j]=min(lst[j],dp[s][j-1])
# print(lst)
# print(dp[0][:])
# print(dp[1][:])
# print(dp[K][:])
return dp[K][N-1]
def main():
N,K=map(int,sys.stdin.readline().strip().split())
cards=list(map(int,sys.stdin.readline().strip().split()))
# cards=list(filter(lambda x:x<K,cards))
# N=len(cards)
cards.sort()
c1i=list(range(N))
def unneccesity(h):
if cards[h]>=K:
return False
else:
c=cards[h]
cards[h]=0
ret=findminsum(cards,K-c,N)>=K
cards[h]=c
return ret
#nn=0
nn=biser(ci,unneccesity)
# for i in range(N):
# if cards[i]<K:
# c=cards[i]
# cards[i]=0
# if findminsum(cards,K-c,N)>=K:
# nn+=1
# cards[i]=c
# else:
# break
print(nn+1)
def main2():
N,K=map(int,sys.stdin.readline().strip().split())
cards=list(map(int,sys.stdin.readline().strip().split()))
mask=lambda c: (1<<(K))-(1<<c)
def isunnec(i):
c=cards[i]
if c>K:
return False
cards[i]=0
ret=0
for x in cards:
if x!=0:
ret=(((ret+1)<<x)|ret )&mask(0)
cards[i]=c
# print(i,bin(ret&mask(K-c)))
if ret&mask(K-c)>0:
return False
else:
return True
nn=biser(list(range(N)),isunnec)
print(nn+1)
# for x in range(N):
# isunnec(x)
if __name__=='__main__':
#main()
main2()
|
s569182278 | p03782 | u543954314 | 1587743339 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 155340 | 620 | n, k = map(int,input().split())
a = list(map(int,input().split()))
def trans(v):
l = [0]*(k+1)
for i in range(k+1):
l[i] = (v&1)
v >>= 1
return l
a.sort()
lef = [1]*n
rig = [1]*n
mask = (1 << (k+1)) - 1
for i in range(n-1):
lef[i+1] = lef[i] | (lef[i] << a[i]) & mask
rig[-i-2] = rig[-i-1] | (rig[-i-1] << a[-i-1]) & mask
ok = -1
ng = n
while ng - ok > 1:
mid = (ng + ok) // 2
lc = lef[mid]
rc = rig[mid]
cov = ((1 << k) - 1) ^ ((1 << (k - a[mid])) - 1)
for i in range(k+1):
if lc & 1 and rc & cov:
ng = mid
break
lc >>= 1
cov >>= 1
else:
ok = mid
print(ok + 1) |
s248207316 | p03782 | u620480037 | 1585272929 | Python | PyPy3 (2.4.0) | py | Runtime Error | 271 | 43228 | 1120 | N,K=map(int,input().split())
b=list(map(int,input().split()))
b.sort()
a=[]
for i in range(N):
if b[i]<K:
a.append(b[i])
N=len(a)
ans=0
#print(bin((1<<K)>>1))
C=[1]
n=1
for i in range(N):
n=n|n<<a[i]
n%=(1<<K)
C.append(n)
#print(C)
#print(bin(n))
if N<=10:
for i in range(N):
n=C[i]
for j in range(i+1,N):
n=n|n<<a[j]
n%=(1<<K)
if n < (1<<K)>>a[i]:
ans+=1
else:
break
print(ans)
else:
a+=[10**9]
H=N
L=0
while abs(H-L)>4:
Mid=(H+L)//2
#print(H,Mid,L)
n=1
for i in range(N):
if i==Mid:
continue
else:
n=n|n<<a[j]
n%=(1<<K)
if n < (1<<K)>>a[i]:
H=Mid
else:
L=Mid
for j in range(max(0,L-5),N):
n=1
for i in range(N):
if i==j:
continue
else:
n=n|n<<a[j]
n%=(1<<K)
if n < (1<<K)>>a[i]:
print(j)
exit()
|
s157942843 | p03782 | u620480037 | 1585106383 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2106 | 44508 | 848 | N,K=map(int,input().split())
b=list(map(int,input().split()))
b.sort()
a=[]
for i in range(N):
if b[i]<K:
a.append(b[i])
N=len(a)
ans=0
#print(bin((1<<K)>>1))
C=[1]
n=1
for i in range(N):
n=n|n<<a[i]
n%=(1<<K)
C.append(n)
#print(C)
#print(bin(n))
P=N//2
n=C[P]
for x in range(P+1,N):
n=n|n<<a[x]
n%=(1<<K)
if n < (1<<K)>>a[P]:
F=0
else:
F=1
if F==0:
for i in range(N):
n=C[i]
for j in range(i+1,N):
n=n|n<<a[j]
n%=(1<<K)
if n < (1<<K)>>a[i]:
ans+=1
else:
break
print(ans)
else:
ans=N//2
P=N//2
for i in range(P+1,N):
n=C[i]
for j in range(i+1,N):
n=n|n<<a[j]
n%=(1<<K)
if n < (1<<K)>>a[i]:
ans+=1
else:
break
print(ans)
|
s149310710 | p03782 | u941407962 | 1581081794 | Python | PyPy3 (2.4.0) | py | Runtime Error | 193 | 41712 | 445 | N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
#dpm = [+1) for _ in range(N+1)]
dpm = [0]*(N+1)
dpm[0] = 1<<(K-1)
for i, a in enumerate(A):
dpm[i+1] = dpm[i] | (dpm[i] >> a)
r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
for j in range(a):
if dp2 & tmp:
break
dpm[N-i-1] >>= 1
else:
r += 1
dp2 |= dp2<<a
dp2 &= (1<<K)-1
print(r)
|
s092557025 | p03782 | u102461423 | 1575517631 | Python | Python (3.4.3) | py | Runtime Error | 71 | 3572 | 830 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
"""
・「必要」とは~~が存在
・x を含まない、[K-x,K) 内の総和が存在
・集合を指定すると、ある値段より上側
・全体としても単調性がある
"""
N,K,*A = map(int,read().split())
A.sort()
A = [x if x <= K else K + 1 for x in A]
mask = (1 << K) - 1
def test(x):
# x番目は必要
if A[x] > K:
return True
dp = 1
for a in itertools.chain(A[:x], A[x+1:]):
dp |= (dp << a)
dp &= mask
dp >>= (K - x)
return (dp > 0)
left = -1 # 必要
right = N # 不要
while left + 1 < right:
x = (left + right) // 2
if test(x):
right = x
else:
left = x
answer = left + 1
print(answer) |
s719497783 | p03782 | u102461423 | 1575517287 | Python | Python (3.4.3) | py | Runtime Error | 71 | 3572 | 794 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
"""
・「必要」とは~~が存在
・x を含まない、[K-x,K) 内の総和が存在
・集合を指定すると、ある値段より上側
・全体としても単調性がある
"""
N,K,*A = map(int,read().split())
A.sort()
A = [x if x <= K else K + 1 for x in A]
mask = (1 << K) - 1
def test(x):
# x 番目を抜いて
dp = 1
for a in itertools.chain(A[:x], A[x+1:]):
dp |= (dp << a)
dp &= mask
dp >>= (K - x)
return (dp > 0)
left = -1 # 必要
right = N # 不要
while left + 1 < right:
x = (left + right) // 2
if test(x):
right = x
else:
left = x
answer = right
print(answer) |
s305865564 | p03782 | u543954314 | 1571325689 | Python | Python (3.4.3) | py | Runtime Error | 2128 | 396788 | 957 | _,k = map(int,input().split())
a = list(filter(lambda x:x<k,list(map(int,input().split()))))
n = len(a)
a.sort(reverse=True)
dpf = [[False]*k for _ in range(n)]
dpb = [[False]*k for _ in range(n)]
dpf[0][0] = True
dpb[-1][0] = True
for i in range(n-1):
wf = a[i]
wb = a[-(i+1)]
for j in range(k):
if dpf[i][j]:
dpf[i+1][j] = True
if j+wf < k:
dpf[i+1][j+wf] = True
if dpb[-(i+1)][j]:
dpb[-(i+2)][j] = True
if j+wb < k:
dpb[-(i+2)][j+wb] = True
def check(v):
w = a[v]
im = [0]*(k+1)
lf = dpf[v]
lb = dpb[v]
for i in range(k):
if lb[i]:
if k-i <= 0:
continue
im[max(k-w-i,0)] += 1
im[k-i] -= 1
if lf[0] and im[0]>0:
return False
for i in range(1,k):
im[i] += im[i-1]
if lf[i] and im[i]>0:
return False
return True
ng = -1
ok = n
while ok-ng > 1:
mid = (ok+ng)//2
if check(mid):
ok = mid
else:
ng = mid
print(n-ok)
|
s196651233 | p03782 | u543954314 | 1571325485 | Python | Python (3.4.3) | py | Runtime Error | 2128 | 396788 | 949 | _,k = map(int,input().split())
a = list(filter(lambda x:x<k,list(map(int,input().split()))))
n = len(a)
a.sort(reverse=True)
dpf = [[False]*k for _ in range(n)]
dpb = [[False]*k for _ in range(n)]
dpf[0][0] = True
dpb[0][0] = True
for i in range(n-1):
wf = a[i]
wb = a[-(i+1)]
for j in range(k):
if dpf[i][j]:
dpf[i+1][j] = True
if j+wf < k:
dpf[i+1][j+wf] = True
if dpb[i][j]:
dpb[i+1][j] = True
if j+wb < k:
dpb[i+1][j+wb] = True
def check(v):
w = a[v]
im = [0]*(k+1)
lf = dpf[v]
lb = dpb[n-v-1]
for i in range(k):
if lb[i]:
if k-i <= 0:
continue
im[max(k-w-i,0)] += 1
im[k-i] -= 1
if lf[0] and im[0]>0:
return False
for i in range(1,k):
im[i] += im[i-1]
if lf[i] and im[i]>0:
return False
return True
ng = -1
ok = n
while ok-ng > 1:
mid = (ok+ng)//2
if check(mid):
ok = mid
else:
ng = mid
print(n-ok)
|
s657958538 | p03782 | u543954314 | 1571322985 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 565 | 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()
|
s832481597 | p03782 | u543954314 | 1571251246 | Python | PyPy3 (2.4.0) | py | Runtime Error | 179 | 39280 | 517 | n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
hi = -1
lo = n
while lo-hi>1:
mid = (lo+hi)//2
if a[mid] >= k:
hi = mid
else:
lo = mid
ng = hi
ok = n
while ok-ng > 1:
mid = (ok+ng)//2
dp = [False]*(k+1)
dp[0] = True
f = 1
for j in range(n):
if j == mid:
f = 0
continue
w = a[j]
new = dp.copy()
for i in range(k-w+1):
new[i+w] |= dp[i]
dp = new
if any(dp[k-a[mid]:k]):
ng = mid
else:
ok = mid
print(n-ok)
|
s609155781 | p03782 | u794173881 | 1561343652 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2180 | 1138312 | 607 | n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
def subset_sum(a):
n = len(a)
dp = [[0]*(k + 1) for i in range(n + 1)]
dp[0][0] = 1
for i in range(n):
for j in range(k+1):
if j - a[i] < 0:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = dp[i][j] + dp[i][j - a[i]]
return dp[n]
ok = -1
ng = n
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
li = a[0:mid] + a[mid+1:]
dp = subset_sum(li)
if max(dp[k-a[mid]:k]) == 0:
ok = mid
else:
ng = mid
print(ng) |
s948839198 | p03782 | u794173881 | 1561343614 | Python | Python (3.4.3) | py | Runtime Error | 2139 | 585608 | 607 | n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
def subset_sum(a):
n = len(a)
dp = [[0]*(k + 1) for i in range(n + 1)]
dp[0][0] = 1
for i in range(n):
for j in range(k+1):
if j - a[i] < 0:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = dp[i][j] + dp[i][j - a[i]]
return dp[n]
ok = -1
ng = n
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
li = a[0:mid] + a[mid+1:]
dp = subset_sum(li)
if max(dp[k-a[mid]:k]) == 0:
ok = mid
else:
ng = mid
print(ng) |
s569194649 | p03782 | u218843509 | 1548746392 | Python | PyPy3 (2.4.0) | py | Runtime Error | 335 | 40048 | 697 | import sys
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
#print(a)
fr = 0
ba = n+1
def check(mi):
x = a[mi-1]
if x >= k:
return True
#print(mi)
dp = [False] * (k+1)
dp[0] = True
for i in range(n):
if i == mi-1:
continue
y = a[i]
for j in range(k, -1, -1):
if j >= y:
dp[j] = dp[j] | dp[j-y]
if sum(dp[k-x:k]):
return True
else:
return False
if not check(1):
print(0)
sys.exit()
if check(n+1):
print(n)
sys.exit()
while ba-fr > 1:
mi = (ba+fr+1) // 2
if check(mi):
ba = mi
else:
fr = mi
print(fr) |
s929747145 | p03782 | u619631862 | 1544593284 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2166 | 909192 | 951 | def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
[N,K]=i2()
a=i2()
a.sort()
def f(b,c):
dp=[[0 for i in range(K)]for j in range(len(b))]
dp[0][b[0]]=1
d=0
for i in range(1,len(b)):
for j in range(K):
dp[i][j]+=dp[i-1][j]
if j-b[i]>=0:dp[i][j]+=dp[i-1][j-b[i]]
if dp[i][j]==1 and d<j:d=j
return K-c <= d
def ff():
low = 0
high = len(a) - 1
while high-low>1:
mid = (low + high) // 2
if 0<mid<N-1:
b=a[:mid]+a[mid+1:]
elif mid==N-1:
b=a[:mid]
else:
b=a[mid+1:]
if f(b,a[mid]):
high = mid
else:
low = mid
return high
if f(a[1:],a[0]):
print(0)
elif not f(a[:N-1],a[N-1]):
print(N)
else:
print(ff()) |
s563701937 | p03782 | u236127431 | 1544215046 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2108 | 42896 | 522 | from bisect import bisect
N,K=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
def dp(n):
d=[False]*(K+1)
d[0]=True
for i in range(N):
if i!=n:
for w in range(K)[::-1]:
if w+a[i]<=K and d[w]:
d[w+a[i]]=True
for i in range(K-a[n],K):
if d[i]:
return True
return False
l,r=0,N-1
while r-l>1:
m=(l+r)//2
if dp(m):
r=m
else:
l=m
if r==N-1 and not dp(N-1):
print(N)
elif not dp(r):
print(r+1)
elif not dp(l):
print(l+1)
else:
print(l)
|
s791043340 | p03782 | u177398299 | 1538434694 | Python | PyPy3 (2.4.0) | py | Runtime Error | 172 | 39408 | 667 | # https://beta.atcoder.jp/contests/arc070/submissions/2980516
from bisect import bisect_left
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
A = A[:bisect_left(A, K)]
dp = [False] * K
dp[0] = True
curr_max = 0
ans = len(A)
for i, a in reversed(enumerate(A)):
# a[i - 1]を使ってa[i]が必要ならa[i - 1]も必要
# a[i]より大きな値を使って判定すればいい
if curr_max + a >= K:
ans = i
f = True
for j in range(min(curr_max, K - a - 1), -1, -1):
if dp[j]:
dp[j + a] = True
if f:
curr_max = max(curr_max, j + a)
f = False
print(ans) |
s066954572 | p03782 | u218843509 | 1535181307 | Python | Python (3.4.3) | py | Runtime Error | 2116 | 199284 | 1026 | N, K = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
def check(i):
if i == 0:
b = a[1:]
elif i == N - 1:
b = a[:N - 1]
else:
b = a[:i] + a[i+1:]
#print(b)
ok = False
dp = [[False] * K for _ in range(N - 1)]
dp[0][b[0]] = True
if K - a[i] <= b[0] < K:
ok = True
for j in range(1, N - 1):
for k in range(1, K):
if dp[j - 1][k] == True:
dp[j][k] = True
elif k > b[j]:
if dp[j - 1][k - b[j]] == True:
dp[j][k] = True
if dp[j][k] == True and K - a[i] <= k < K:
ok = True
if ok:
#del b, dp
return True
else:
#del b, dp
return False
def bi_search(lower, upper):
#print(lower, upper)
mid = (lower + upper) // 2
#print(mid)
if check(mid) == False and check(mid + 1) == True:
#print("hoge")
return mid + 1
elif mid == 0 and check(mid) == True:
return 0
elif mid == N - 2 and check(mid + 1) == False:
return N
elif check(mid) == True:
return bi_search(lower, mid)
else:
return bi_search(mid, upper)
print(bi_search(0, N - 1)) |
s098434287 | p03782 | u123518636 | 1535083986 | Python | PyPy2 (5.6.0) | py | Runtime Error | 2106 | 35688 | 2493 | #!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq
# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7
def solve(f):
n, k = f.read_int_list()
a = f.read_int_list()
a.sort(reverse=True)
# if n > 400: return 0
def check(ai):
aa = a[:]
aa.remove(ai)
# dp = [False] * k
dp = [False] * (2*k)
dp[0] = dp[k] = True
for i in xrange(n-1):
ofs0 = (i % 2) * k
ofs1 = ((i+1)%2) * k
for j in xrange(k):
if dp[ofs0+j] and aa[i] + j < k:
dp[ofs1+aa[i]+j] = True
if (n-1)%2 == 0:
return any(dp[k-ai:k])
else:
return any(dp[2*k-ai:])
au = list(set(a))
au.sort(reverse=True)
mi = -1
ma = len(au)
while ma - mi > 1:
mid = (ma+mi)/2
if check(au[mid]):
mi = mid
else:
ma = mid
a.sort()
return bisect.bisect_right(a, au[ma])
# need = 0
# for i in xrange(n):
# if check(i): need += 1
#
# return n-need
class Reader(object):
def __init__(self, filename=None):
self.file = open(filename) if filename is not None else None
self.case = 1
def __readline(self):
return self.file.next().strip() if self.file else raw_input()
def next_case(self):
self.file.next()
self.case += 1
def read_int(self): return int(self.__readline())
def read_float(self): return float(self.__readline())
def read_long(self): return long(self.__readline())
def read_decimal(self): return decimal.Decimal(self.__readline())
def read_str(self): return self.__readline()
def read_int_list(self): return map(int, self.__readline().split())
def read_float_list(self): return map(float, self.__readline().split())
def read_long_list(self): return map(long, self.__readline().split())
def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
def read_str_list(self): return self.__readline().split()
if __name__ == '__main__':
filename = sys.argv[1] if len(sys.argv) > 1 else None
f = Reader(filename)
if f.file:
while True:
print "Case #%d\n"%f.case, solve(f)
try:
f.next_case()
except StopIteration:
break
else:
print solve(f)
|
s705914014 | p03782 | u340781749 | 1533957014 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2126 | 331656 | 1687 | import bisect
def preliminary(k, aaa):
dp = [False] * k
dp[0] = True
curr_max = 0
fwd = {}
pa = aaa[0]
pdp, ppdp = dp[:], None
for a in aaa:
if pa != a:
fwd[pa] = ppdp
for i in range(min(curr_max, k - a - 1), -1, -1):
if dp[i]:
dp[i + a] = True
curr_max += a
pa = a
ppdp = pdp
pdp = dp[:]
fwd[pa] = ppdp
dp = [False] * k
dp[0] = True
curr_max = 0
bwd = {}
pa = 0
pdp = []
for a in reversed(aaa):
if pa != a:
bwd[a] = [i for i, v in enumerate(pdp) if v][1:]
for i in range(min(curr_max, k - a - 1), -1, -1):
if dp[i]:
dp[i + a] = True
curr_max += a
pa = a
pdp = dp[:]
return fwd, bwd
def get_judge(k, aaa):
fwd, bwd = preliminary(k, aaa)
cache = [None] * k
def judge(m):
am = aaa[m]
if cache[am] is None:
dp = fwd[am]
ndp = dp[:]
for i in bwd[am]:
for j in range(k - i - 1, -1, -1):
if dp[j]:
ndp[i + j] = True
cache[am] = any(ndp[-am:])
return cache[am]
return judge
def solve(k, aaa):
if sum(aaa) < k:
return n
aaa.sort()
aaa = aaa[:bisect.bisect_left(aaa, k)]
judge = get_judge(k, aaa)
l = 0
r = len(aaa) - 1
m = (l + r) // 2
while l <= r:
if judge(m):
r = m - 1
else:
l = m + 1
m = (l + r) // 2
return l
n, k = map(int, input().split())
aaa = list(map(int, input().split()))
print(solve(k, aaa))
|
s206606878 | p03782 | u340781749 | 1533954643 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 39408 | 1555 | import bisect
def preliminary(k, aaa):
dp = [False] * k
dp[0] = True
curr_max = 0
fwd = []
for a in aaa:
for i in range(min(curr_max, k - a - 1), -1, -1):
if dp[i]:
dp[i + a] = True
fwd.append(dp.copy())
curr_max += a
dp = [False] * k
dp[0] = True
curr_max = 0
bwd = []
for a in reversed(aaa):
for i in range(min(curr_max, k - a - 1), -1, -1):
if dp[i]:
dp[i + a] = True
bwd.append([i for i, v in enumerate(dp) if v][1:])
curr_max += a
bwd.reverse()
dummy = [False] * k
dummy[0] = True
fwd.append(dummy)
bwd.append([])
return fwd, bwd
def get_judge(k, aaa):
fwd, bwd = preliminary(k, aaa)
cache = [None] * k
def judge(m):
am = aaa[m]
if cache[am] is None:
dp = fwd[m - 1]
for i in bwd[m + 1]:
for j in range(k - i - 1, -1, -1):
if dp[j]:
dp[i + j] = True
cache[am] = any(dp[-am:])
return cache[am]
return judge
def solve(k, aaa):
if sum(aaa) < k:
return n
aaa.sort()
aaa = aaa[:bisect.bisect_left(aaa, k)]
judge = get_judge(k, aaa)
l = 0
r = len(aaa) - 1
m = (l + r) // 2
while l <= r:
if judge(m):
r = m - 1
else:
l = m + 1
m = (l + r) // 2
return l
n, k = map(int, input().split())
aaa = list(map(int, input().split()))
print(solve(k, aaa))
|
s997662596 | p03782 | u340781749 | 1533953293 | Python | PyPy3 (2.4.0) | py | Runtime Error | 178 | 39280 | 1583 | import bisect
def preliminary(k, aaa):
dp = [False] * k
dp[0] = True
curr_max = 0
fwd = []
for a in aaa:
for i in range(min(curr_max, k - a - 1), -1, -1):
if dp[i]:
dp[i + a] = True
fwd.append(dp.copy())
curr_max += a
dp = [False] * k
dp[0] = True
curr_max = 0
bwd = []
for a in reversed(aaa):
for i in range(min(curr_max, k - a - 1), -1, -1):
if dp[i]:
dp[i + a] = True
bwd.append([i for i, v in enumerate(dp) if v][1:])
curr_max += a
bwd.reverse()
dummy = [False] * k
dummy[0] = True
fwd.append(dummy)
bwd.append([])
return fwd, bwd
def get_judge(k, aaa):
fwd, bwd = preliminary(k, aaa)
cache = [None] * k
def judge(m):
am = aaa[m]
if cache[am] is None:
dp = fwd[m - 1]
for i in bwd[m + 1]:
for j in range(k - i - 1, -1, -1):
if dp[j]:
dp[i + j] = True
cache[am] = any(dp[-am:])
return cache[am]
return judge
def solve(k, aaa):
aaa.sort()
uk = bisect.bisect_left(aaa, k)
aaa = aaa[:uk]
judge = get_judge(k, aaa)
l = 0
r = len(aaa) - 1
m = (l + r) // 2
while l <= r:
if judge(m):
r = m - 1
else:
l = m + 1
m = (l + r) // 2
return l
n, k = map(int, input().split())
aaa = list(map(int, input().split()))
# n = 5000
# k = 5000
# aaa = list(range(1, n + 1))
print(solve(k, aaa))
|
s599946866 | p03782 | u340781749 | 1533949988 | Python | Python (3.4.3) | py | Runtime Error | 2112 | 62940 | 996 | import bisect
import numpy as np
from scipy.ndimage.interpolation import shift
def preliminary(k, aaa):
dp = np.zeros(k, np.uint8)
dp[0] = 1
fwd = []
for a in aaa:
dp |= shift(dp, a)
fwd.append(dp.copy())
dp = np.zeros(k, np.uint8)
dp[0] = 1
bwd = []
for a in reversed(aaa):
dp |= shift(dp, a)
bwd.append(np.where(dp)[0])
bwd.reverse()
fwd.append(np.zeros(k, np.uint8))
bwd.append([0])
return fwd, bwd
def solve(k, aaa):
aaa.sort()
uk = bisect.bisect_left(aaa, k)
aaa = aaa[:uk]
fwd, bwd = preliminary(k, aaa)
l = 0
r = len(aaa) - 1
m = (l + r) // 2
while l <= r:
dp = fwd[m - 1]
for i in bwd[m + 1][1:]:
dp |= shift(dp, i)
if dp[-aaa[m]:].any():
r = m - 1
else:
l = m + 1
m = (l + r) // 2
return l
n, k = map(int, input().split())
aaa = list(map(int, input().split()))
print(solve(k, aaa))
|
s659991936 | p03782 | u340781749 | 1533947208 | Python | PyPy3 (2.4.0) | py | Runtime Error | 169 | 38384 | 613 | import bisect
import numpy as np
from scipy.ndimage.interpolation import shift
def judge(e):
ae = aaa[e]
dp = np.zeros(k, np.uint8)
dp[0] = 1
for i, a in enumerate(aaa):
if i == e:
continue
dp |= shift(dp, a)
return dp[-ae:].any()
def solve(k, aaa):
l = 0
r = bisect.bisect_left(aaa, k) - 1
m = (l + r) // 2
while l <= r:
if judge(m):
r = m - 1
else:
l = m + 1
m = (l + r) // 2
return l
n, k = map(int, input().split())
aaa = list(map(int, input().split()))
aaa.sort()
print(solve(k, aaa))
|
s394758443 | p03782 | u075012704 | 1532365082 | Python | PyPy3 (2.4.0) | py | Runtime Error | 701 | 43740 | 819 | N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted([a for a in A if a < K])
N = len(A)
S = sum(A)
# あああああああああああああああああああ\(^o^)/
if S - A[0] < K:
print(0)
exit()
l, r = -1, N
while r - l > 1:
m = (l + r) // 2
B = A[:m] + A[m + 1:]
if S - A[m] < K - A[m]:
l = m
continue
dp = [False] * (K + 1)
dp[0] = True
flg= False
for i in range(N - 1):
for j in range(K + 1)[::-1]:
if B[i] > j:
continue
else:
dp[j] = dp[j - B[i]]
if dp[j] and K-A[m] <= j < K:
r = m
flg = True
break
if flg:
flg = False
break
else:
l = m
print(r)
|
s049522693 | p03782 | u777923818 | 1515111038 | Python | PyPy3 (2.4.0) | py | Runtime Error | 194 | 40048 | 689 | # -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from copy import deepcopy
from operator import add
from itertools import accumulate
N, K = inpl()
A = sorted(inpl())
S = list(accumulate(A, add))
A = A[::-1]
DP = [False for _ in range(K)]
DP[0] = 1
OK = [False for _ in range(N)]
for i, a in enumerate(A):
DP0 = deepcopy(DP)
if a >= K:
OK[i] = True
continue
for j, d in enumerate(DP0[-S[::-1][i]:], max(0, K-S[::-1][i])):
if d:
if j + a >= K:
OK[i] = True
break
else:
DP[j+a] = True
if sum(OK) == 0:
print(N)
else:
print(OK[::-1].index(True)) |
s951561926 | p03782 | u777923818 | 1515110974 | Python | PyPy3 (2.4.0) | py | Runtime Error | 186 | 39664 | 695 | # -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from copy import deepcopy
from operator import add
from itertools import accumulate
N, K = inpl()
A = sorted(inpl())
S = list(accumulate(A, add))
A = A[::-1]
DP = [False for _ in range(K)]
DP[0] = 1
OK = [False for _ in range(N)]
for i, a in enumerate(A):
DP0 = deepcopy(DP)
if a >= K:
OK[i] = True
continue
for j, d in enumerate(DP0[-S[::-1][i]:], max(0, K-S[::-1][i])):
if d:
if j + a >= K:
OK[i] = True
break
else:
DP[j+a] = True
if sum(OK) == 0:
print(N)
else:
print(OK[::-1].index(True)) |
s252207952 | p03782 | u433219236 | 1491007887 | Python | Python (2.7.6) | py | Runtime Error | 2117 | 213480 | 716 | # coding: utf-8
n, k = map(int, raw_input().split())
a = list(map(int, raw_input().split()))
a.sort()
left = 0
right = n - 1
while left != right:
mid = (left + right + 1) / 2
dp = [[0 for j in range(k + 1)] for i in range(n + 1)]
dp[0][0] = 1
for i in range(n):
for j in range(k + 1):
keep = dp[i][j]
if j - a[i] >= 0:
if i != mid:
if dp[i][j - a[i]] == 1:
keep = 1
dp[i + 1][j] = keep
flag = 0
for i in range(k - a[mid], k):
if dp[n][i] == 1:
flag = 1
break
if flag == 1:
right = mid - 1
else:
left = mid
print(left + 1)
|
s263927391 | p03782 | u762603420 | 1490731277 | Python | Python (3.4.3) | py | Runtime Error | 2122 | 222716 | 681 | N, K = list(map(int, input().split()))
nums = list(map(int, input().split()))
nums.sort()
if sum(nums) < K or nums[0] >= K:
print(str(N))
quit()
dp = [[False for i in range(0, N)] for j in range(0, K)]
import numpy as np
res = N
for i in range(0, N):
dp_arr = np.array(dp[:])
dp_arr[0, :] = True
for j in range(1, K):
idx = 1
for k in range(0, N):
if k == i or j - nums[k] < 0:
continue
if dp_arr[j - nums[k]][idx - 1]:
dp_arr[j][idx] = True
idx += 1
for j in range(K - nums[i], K):
if sum(dp_arr[j]) > 0:
res -= 1
break
print(str(res)) |
s316545489 | p03782 | u762603420 | 1490726871 | Python | Python (3.4.3) | py | Runtime Error | 2117 | 214900 | 888 | N, K = list(map(int, input().split()))
nums = list(map(int, input().split()))
nums.sort()
if sum(nums) < K or nums[0] >= K:
print(str(N))
quit()
dp = [[0 for i in range(0, N)] for j in range(0, K)]
idx = 0
for i in range(1, K):
for j in range(0, N):
s = sum(nums[:j+1])
if s >= i:
dp[i][j] = s
res = N
for i in range(1, N):
for j in range(K - nums[i], K):
find = False
for k in range(0, N):
if k == i:
continue
if k < i:
if dp[j][k] < K and dp[j][k] + nums[i] >= K:
res -= 1
find = True
break
else:
if dp[j][k] >= K and dp[j][k] - nums[i] < K:
res -= 1
find = True
break
if find:
break
print(str(res)) |
s826681028 | p03782 | u107077660 | 1490061456 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3732 | 739 | N, K = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
S = sum(A)
if S < K:
print(N)
exit()
elif A[0] >= K:
print(0)
exit()
def is_necessary(n):
if A[n] >= K:
return True
dp = [False]*K
dp[0] = True
dp2 = [False]*K
dp2[0] = True
can_make = []
can_make2 = [0]
for i in range(N):
if i == n:
continue
elif A[i] >= K:
break
a = A[i]
for j in can_make2:
if dp2[j] and j+a < K and not dp2[j+a]:
if j + a >= K - A[n]:
return True
dp[j+a] = True
can_make.append(j+a)
can_make2.extend(can_make)
can_make = []
dp2 = dp[:]
return False
l = -1
r = N
while r - l > 1:
m = (r+l)//2
while A[m-1] == A[m]:
m -= 1
if is_necessary(m):
r = m
else:
l = m
print(l+1) |
s288359704 | p03782 | u637175065 | 1489933519 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 10428 | 984 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n,k = LI()
a = sorted(LI(), key=lambda x: -x)
ii = [2**i for i in range(k)]
s = [0 for _ in range(k)]
rs = 0
for i in range(n):
ai = a[i]
iii = ii[i]
if ai >= k:
rs |= iii
continue
for j in range(k-1,0,-1):
sj = s[j]
if sj:
if j+ai < k:
s[j+ai] |= sj
s[j+ai] |= iii
else:
rs |= sj
rs |= iii
s[ai] |= iii
r = n
for iii in ii:
if (rs & iii) > 0:
r -= 1
return r
print(main())
|
s161030984 | p03782 | u927220534 | 1489890011 | Python | PyPy2 (5.6.0) | py | Runtime Error | 2107 | 56092 | 1040 | from sys import stdin
rr = lambda: stdin.readline().strip()
rrI = lambda: int(rr())
rrM = lambda: map(int, rr().split())
N,K = rrM()
A = rrM()
#N,K,A = 3,6,[1,4,3]
#N,K,A = 5,20,[3,1,4,1,5]
#N,K,A = 6,20,[10,4,3,10,25,2]
nogood = sum(A) < K
A = [x for x in A if x < K]
N = len(A)
#For each x, among set S = A-x,
#necessary if there's no subset of S summing in [K-x, K).
dp = [ None for _ in xrange(K) ]
#dp[k][i] = a subset summing to k that doesnt use i
def search(index, sum_, indices):
if index == N: return
newsum = sum_ + A[index]
if newsum >= K: return
if dp[newsum] is None:
dp[newsum] = set(indices)
else:
dp[newsum] &= set(indices)
search(index+1, sum_, indices)
search(index+1, newsum, indices|{index} )
search(0,0,set())
#i in dp[k] means summing to k must use i
#dp[k] is None means cant sum to k
#print dp
ans = 0
for i, x in enumerate(A):
for k in xrange(K-x, K):
if i in (dp[k] or ()):
ans += 1
break
print ans if not nogood else N
|
s447691053 | p03782 | u477320129 | 1489888782 | Python | PyPy3 (2.4.0) | py | Runtime Error | 570 | 41328 | 539 | def solve(N, K, A):
assert N <= 400 and K <= 400
count = 0
for i, a in enumerate(A):
flags = [False] * K
flags[0] = True
for j, aa in enumerate(A):
if i == j or aa >= K:
continue
for k in range(K-1, aa-1, -1):
flags[k] |= flags[k-aa]
if any(flags[-a:]):
count += 1
return N - count
if __name__ == "__main__":
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(solve(N, K, A))
|
s921858465 | p03782 | u177721681 | 1489888384 | Python | Python (2.7.6) | py | Runtime Error | 14 | 2948 | 489 | import sys
N, K = map(int, sys.stdin.readline().split())
cards = sorted(map(int, sys.stdin.readline().split()) , reverse=True)
i = 0
s = 0
while i < N:
s += cards[i]
if s >= K:
s = 0
j = i
i += 1
if s > K:
print N
else:
print N-j-1 |
s144645404 | p03783 | u823871776 | 1552087198 | Python | Python (3.4.3) | py | Runtime Error | 27 | 4340 | 1283 | import math
n = int(input())
N = 400
if n > N: exit()
l = [0]*n
r = [0]*n
for i in range(n):
l[i], r[i] = list(map(int, input().split()))
dp = [[1000 for i in range(N)] for j in range(n)]
for i in range(N): #最初の段は埋めておく。
dp[0][i] = abs(l[ni]-i)
if i < l[ni]:
d = l[ni] - i
elif r[ni] < i:
d = i - r[ni]
else:
d = 0
dp[0][i] = d
for ni in range(1,n): # 何段目で?
for xj in range(N): # どこに接地させる?
# このブロックをxjに持っていくコスト
if xj < l[ni]:
d = l[ni] - xj
elif r[ni] < xj:
d = xj - r[ni]
else:
d = 0
# 前のブロックで、xjに設置している中で最もコストの低いものに、今回のコストを加える
min_cost = 1000
for xk in range(N):
d2 = 0
if xk < xj:
if xj <= xk+r[ni-1]:
min_cost = min(min_cost, dp[ni-1][xj] + d2 )
elif xj < xk:
if xk <= xj+r[ni]:
min_cost = min(min_cost, dp[ni-1][xj] + d2 )
else:
min_cost = min(min_cost, dp[ni-1][xj] + d2)
dp[ni][xj] = min_cost+d
print(min(dp[n-1])) |
s911515682 | p03783 | u823871776 | 1552002981 | Python | Python (3.4.3) | py | Runtime Error | 113 | 9332 | 586 | n = int(input())
if n>400: exit()
l = [0]*n
r = [0]*n
for i in range(n):
l[i], r[i] = list(map(int, input().split()))
N = 400+1
dp = [[0 for i in range(N)] for j in range(n)]
# 一番上のブロックを動かした時のコスト
for i in range(N):
if r[0] < i: d = i-r[0]
elif i < l[0]: d = l[0]-i
else: d = 0
dp[0][i] = d
# 順番にコストを計算していく
for ni in range(1,n+1):
for i in range(N):
if r[ni] < i: d = i-r[ni]
elif i < l[ni]: d = l[ni]-i
else: d = 0
dp[ni][i] = d + dp[ni-1][i]
print(min(dp[n-1])) |
s223387866 | p03783 | u226155577 | 1519613493 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2149 | 61400 | 444 | N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
INF = 10**18
L = max(r for l, r in P)
S = [0]*L
l0, r0 = P[0]
for i in range(L):
S[i] = abs(i - (l0-1))
for i in range(N-1):
l0, r0 = P[i]
l1, r1 = P[i+1]
T = [0]*L
for x in range(L):
r = INF
for y in range(max(0, x-(r0-l0)), min(L, x+(r1-l1)+1)):
r = min(r, S[y])
T[x] = abs(x-(l1-1)) + r
S = T
print(min(S)) |
s505484602 | p03783 | u226155577 | 1519613351 | Python | Python (3.4.3) | py | Runtime Error | 2142 | 27508 | 444 | N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
INF = 10**18
L = max(r for l, r in P)
S = [0]*L
l0, r0 = P[0]
for i in range(L):
S[i] = abs(i - (l0-1))
for i in range(N-1):
l0, r0 = P[i]
l1, r1 = P[i+1]
T = [0]*L
for x in range(L):
r = INF
for y in range(max(0, x-(r0-l0)), min(L, x+(r1-l1)+1)):
r = min(r, S[y])
T[x] = abs(x-(l1-1)) + r
S = T
print(min(S)) |
s785264885 | p03783 | u477320129 | 1489891175 | Python | PyPy3 (2.4.0) | py | Runtime Error | 660 | 65368 | 834 | def solve(N, lefts, rights):
assert 1 <= N <= 400
min_l, max_l = min(lefts), max(lefts)
max_r = max(rights)
assert 1 <= min_l < max_r <= 400
dp = [[float("inf")] * (max_l + 1) for _ in range(N)]
dp = [[0] * (max_l + 1)] + dp
lefts = (1,) + lefts
rights = (max_l,) + rights
for i in range(1, N+1):
pre_length = rights[i-1] - lefts[i-1]
for l in range(1, max_l + 1):
#print("{}, [{}, {}]".format(l, max(1, l-pre_length), l))
dp[i][l] = min(dp[i-1][max(1, l-pre_length):min(rights[i]+1, max_l+1)] or [float("inf")]) + abs(lefts[i]-l)
#print(dp[i])
return(min(dp[-1][1:]))
if __name__ == "__main__":
N = int(input())
lr = [[int(i) for i in input().split()] for _ in range(N)]
lefts, rights = zip(*lr)
print(solve(N, lefts, rights))
|
s649920135 | p03783 | u477320129 | 1489891138 | Python | Python (3.4.3) | py | Runtime Error | 1014 | 29888 | 838 | def solve(N, lefts, rights):
assert 1 <= N <= 400
min_l, max_l = min(lefts), max(lefts)
max_r = max(rights)
assert 1 <= min_l < max_r <= 400
dp = [[float("inf")] * (max_l + 1) for _ in range(N)]
dp = [[0] * (max_l + 1)] + dp
lefts = (1,) + lefts
rights = (max_l,) + rights
for i in range(1, N+1):
pre_length = rights[i-1] - lefts[i-1]
for l in range(1, max_l + 1):
#print("{}, [{}, {}]".format(l, max(1, l-pre_length), l))
dp[i][l] = min(dp[i-1][max(1, l-pre_length):min(rights[i]+1, max_l+1)], default=float("inf")) + abs(lefts[i]-l)
#print(dp[i])
return(min(dp[-1][1:]))
if __name__ == "__main__":
N = int(input())
lr = [[int(i) for i in input().split()] for _ in range(N)]
lefts, rights = zip(*lr)
print(solve(N, lefts, rights))
|
s830111928 | p03783 | u477320129 | 1489891045 | Python | PyPy3 (2.4.0) | py | Runtime Error | 628 | 67160 | 839 | def solve(N, lefts, rights):
assert 1 <= N <= 400
min_l, max_l = min(lefts), max(lefts)
max_r = max(rights)
assert 1 <= min_l < max_r <= 400
dp = [[float("inf")] * (max_l + 1) for _ in range(N)]
dp = [[0] * (max_l + 1)] + dp
lefts = (1,) + lefts
rights = (max_l,) + rights
for i in range(1, N+1):
pre_length = rights[i-1] - lefts[i-1]
for l in range(1, max_l + 1):
#print("{}, [{}, {}]".format(l, max(1, l-pre_length), l))
dp[i][l] = min(dp[i-1][max(1, l-pre_length):min(rights[i]+1, max_l+1)], default=float("inf")) + abs(lefts[i]-l)
#print(dp[i])
return(min(dp[-1][1:]))
if __name__ == "__main__":
N = int(input())
lr = [[int(i) for i in input().split()] for _ in range(N)]
lefts, rights = zip(*lr)
print(solve(N, lefts, rights))
|
s014611543 | p03784 | u828766688 | 1584896612 | Python | PyPy3 (2.4.0) | py | Runtime Error | 274 | 38724 | 63 | A,B = map(int,input().split())
print ("Impossible",flush=True) |
s605419443 | p03784 | u864197622 | 1575525733 | Python | Python (3.4.3) | py | Runtime Error | 119 | 3524 | 352 | A, B = map(int, input().split())
X = [i for i in range(N)]
Y = []
def chk(a, b):
print("?", a, b)
return 1 if input() == "Y" else 0
while X:
if not Y:
Y.append(X.pop())
else:
if chk(Y[-1], X[-1]):
Y.append(X.pop())
else:
Y.pop()
print("!", "".join([str(chk(Y[-1], i)) for i in range(N)])) |
s431397982 | p03784 | u692632484 | 1489899429 | Python | Python (3.4.3) | py | Runtime Error | 576 | 3532 | 422 | temp=input().split()
A=int(temp[0])
B=int(temp[1])
ans=""
count=0
good=0
step=1
if A<B:
print("Impossible")
else:
while True:
print("? "+str(count)+" "+str((count+step)%(A+B)))
if input()=="Y":
good+=1
count+=step
step=1
else:
step+=1
if good==B:
break
person=(count)%(A+B)
for i in range(A+B):
print("? "+str(person)+" "+str(i))
if input()=="Y":
ans+="1"
else:
ans+="0"
print(ans) |
s300432350 | p03785 | u465101448 | 1601254610 | Python | PyPy3 (7.3.0) | py | Runtime Error | 164 | 68652 | 307 | N,C,K = list(map(int,input().split()))
T=[]
for n in range(N):
T.append(int(input_()))
T.sort()
# T
ans = 0
dep = 0
c = 1
for t in T:
# print('===',t)
if c < C and dep > t:
c += 1
else:
ans += 1
dep = t+K
c = 1
# print(ans,dep)
print(ans) |
s061289190 | p03785 | u546440137 | 1600431290 | Python | Python (3.8.2) | py | Runtime Error | 157 | 13304 | 286 | n,c,k = map(int,input().split())
t = list(int(input()) for i in range(n))
t.sort()
bus = 0
leave = t[0] + k
temp = 1
ans = 0
for i in range(1,n):
if temp == 0 or leave < t[i]:
ans += 1
temp = 1
leave = t[i] + k
else:
count += 1
print(ans+1)
|
s620190887 | p03785 | u341267151 | 1599778213 | Python | Python (3.8.2) | py | Runtime Error | 27 | 8976 | 241 | import math
n,c,k=map(int,input().split())
t=[0]*n
s=0
a=0
for i in range(n):
t[i]=int(input())
if i>0 and a>0:
if t[i]-t[i-1]<=k:
s+=(a+n)//c
a=(a+n)%c
else:
s+=math.ceil((a+n)/c)
a=0
print(s) |
s787876376 | p03785 | u411923565 | 1599354338 | Python | PyPy3 (7.3.0) | py | Runtime Error | 202 | 82812 | 473 | #54 A - Airport Bus
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T = sorted(T,reverse = False)
ans = 0
bus = 1
first = T[0]
for i in range(1,N+1):
# T[i] がバスに乗ることができるとき
if (bus < C) and (T[i] <= first + K):
bus += 1
# T[i] がバスに乗ることができないとき
else:
# 新しいバスの first になる
ans += 1
bus = 1
first = T[i]
print(ans+1) |
s373755007 | p03785 | u255898796 | 1598633961 | Python | Python (3.8.2) | py | Runtime Error | 230 | 14044 | 346 | a = [int(s) for s in input().split()]
N = a[0]
si = a[1]
ti = a[2]
s = [int(input()) for i in range(N)]
s = sorted(s)
X = int(0)
ans = int(0)
while N != X:
X += 1
ans += 1
if N == X:
break
for i in range(min([si-1,N-X])):
if s[X + i] <= s[X-1] + ti:
X += 1
else:
break
print(ans) |
s639039660 | p03785 | u255898796 | 1598633790 | Python | Python (3.8.2) | py | Runtime Error | 227 | 13996 | 345 | a = [int(s) for s in input().split()]
N = a[0]
si = a[1]
ti = a[2]
s = [int(input()) for i in range(N)]
s = sorted(s)
X = int(0)
ans = int(0)
while N != X:
X += 1
ans += 1
if N == X:
break
for i in range(min([si-1,N-X])):
if s[X + i] < s[X-1] + ti:
X += 1
else:
break
print(ans) |
s532698287 | p03785 | u476124554 | 1598380169 | Python | PyPy3 (7.3.0) | py | Runtime Error | 98 | 74744 | 755 | n,c,k = map(int,input().split())
t = []
for i in range(n):
t.append(int(input()))
t = sorted(t)
bus = []
ans = 1
for i in range(n):
if len(bus) < c: #バスの定員に余裕があるとき
if not bus: #バスに誰も乗っていなかったらバスに人を乗せる
bus.append(t[i])
elif t[i] <= bus[0] + k:#バスに初めて人が乗った時刻にkを足して、それよりt[i]が小さければバスに乗せる
bus.append(t[i])
else:#上記のelifを満たさない場合(
ans +=1
bus = []
bus.append(t[i])
elif len(bus) == c:
ans +=1
bus = []
bus.append(t[i])
else:
ans +=1
bus = []
print(ans) |
s701505396 | p03785 | u202560873 | 1598251022 | Python | Python (3.8.2) | py | Runtime Error | 197 | 14004 | 456 | N, C, K = [int(x) for x in input().split()]
T = []
for i in range(N):
T.append(int(input()))
T = sorted(T)
T_fast = T[0]
passsengers = 1
buss = 0
for i in range(1, N):
if T[i] - T_fast > K:
T_fast = T[i]
buss += 1
passsengers = 1
else:
passsengers += 1
if passsengers >= C:
T_fast = T[i + 1]
buss += 1
passsengers = 0
if passsengers > 0:
buss += 1
print(buss) |
s777102471 | p03785 | u107915058 | 1597701164 | Python | Python (3.8.2) | py | Runtime Error | 157 | 13336 | 289 | N, C, K = map(int, input().split())
T = list(int(input()) for i in range(N))
T.sort()
bus = 1
passenger = 0
limit = T[0] + K
for i in range(N):
if T[i] <= limit and passenger < c:
passenger += 1
else:
bus += 1
limit = T[i]+K
passenger = 1
print(bus) |
s870986915 | p03785 | u107915058 | 1597700636 | Python | Python (3.8.2) | py | Runtime Error | 24 | 8908 | 134 | bus = 1
time = 0
for i in range(N):
if T[i]-time > K:
bus +=1
time = T[i]
else:
time = time
print(bus) |
s753597411 | p03785 | u637289184 | 1597243548 | Python | PyPy3 (7.3.0) | py | Runtime Error | 204 | 82108 | 251 | N,C,K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
ans=s=0
while s<N:
t=T[s]+K
sm=1
for i in range(s+1,s+c):
if T[i]<t:
sm+=1
else:
break
s+=sm
ans+=1
print(ans)
|
s710051888 | p03785 | u075303794 | 1596849497 | Python | Python (3.8.2) | py | Runtime Error | 1498 | 143776 | 264 | import bisect
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
T.sort()
ans=0
i=0
if T[0]+K>=T[-1]:
print(1)
else:
while True:
if i==N-1:
ans+=1
break
i=bisect.bisect_right(T,T[i]+K)
print(T,i)
ans+=1
print(ans) |
s679263638 | p03785 | u075303794 | 1596849347 | Python | Python (3.8.2) | py | Runtime Error | 213 | 13400 | 248 | import bisect
N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
T.sort()
ans=0
i=0
if T[0]+K>=T[-1]:
print(1)
else:
while True:
if i==N-1:
ans+=1
break
i=bisect.bisect_left(T,T[i]+K)
ans+=1
print(ans) |
s971715411 | p03785 | u591503175 | 1594831257 | Python | Python (3.8.2) | py | Runtime Error | 171 | 13316 | 625 | def resolve():
'''
code here
'''
N, C, K = [int(item) for item in input().split()]
Ts = [int(input()) for _ in range(N)]
Ts.sort()
res = 0
temp_psg = 0
lim = Ts[0] + K
for i in range(N):
temp_psg += 1
if Ts[i] > lim:
res += 1
temp_psg = 1
lim = Ts[i] + K
else:
if temp_psg == C:
res += 1
temp_psg = 0
lim = Ts[i+1] + K
# print(Ts[i], temp_psg, res, lim)
if temp_psg > 0:
res += 1
print(res)
if __name__ == "__main__":
resolve()
|
s837256506 | p03785 | u277429554 | 1593409303 | Python | Python (3.8.2) | py | Runtime Error | 27 | 9084 | 166 | n = int(input())
a = sorted(list(map(int, input().split())))
ans = -1
for i in range(n-1):
if a[i]*2 < a[i+1]:
ans = i
a[i+1] += a[i]
print(n-ans-1) |
s443578483 | p03785 | u277429554 | 1593409106 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9116 | 189 | n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 1
num = sum(l)
for i in range(0,n-1):
num -= l[i]
if num*2<l[i]:
break
ans += 1
print(ans) |
s013495275 | p03785 | u749614185 | 1593391423 | Python | Python (3.8.2) | py | Runtime Error | 79 | 20064 | 245 | import sys
N, C, K = map(int, input().split())
A = list(map(int, sys.stdin.readlines()))+[10**10]
A.sort()
a, c, t = 0, 1, a[0]+k
for i in A[1:]:
if i <= t and c < C:
c += 1
else:
t, c = i + K, 1
a += 1
print(a) |
s328308324 | p03785 | u112007848 | 1592592508 | Python | Python (3.8.2) | py | Runtime Error | 1593 | 144504 | 443 | import bisect
kyaku, teiin, jikan = map(int, input().split(" "))
a=sorted([(int)(input()) for i in range(kyaku)])
print(a)
count = 0
while(True):
print(a)
if len(a) > teiin:
if a[0] + jikan >= a[teiin]:
a = a[teiin:]
else:
a = a[bisect.bisect_left(a, a[0] + jikan):]
else:
if a[0] + jikan >= a[-1]:
count += 1
break
else:
a = a[bisect.bisect_left(a, a[0] + jikan):]
count += 1
print(count) |
s971922093 | p03785 | u810787773 | 1591672541 | Python | Python (3.4.3) | py | Runtime Error | 242 | 7416 | 1938 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
T.sort()
if len(T) == 1:
ans = 1
return(ans)
if C == 1:
return(N)
if C == 2:
while True:
if T[j] + K >= T[i+1]:
i = i + 2
j = i
ans += 1
if j == N:
return ans
elif j == N - 1:
ans += 1
return ans
elif T[j] + K < T[i+1]:
i += 1
j = i
ans += 1
if j == N-1:
ans += 1
return ans
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j == N-1:
ans += 1
return(ans)
elif j == N:
return(ans)
break
else:
i += 1
if (i+1) == N-1:
ans += 1
return(ans)
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans += 1
if j == N-1:
ans += 1
return(ans)
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main())
|
s660476605 | p03785 | u810787773 | 1591672160 | Python | Python (3.4.3) | py | Runtime Error | 253 | 7412 | 1824 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
T.sort()
if len(T) == 1:
ans = 1
return(ans)
if C == 1:
return(N)
if C == 2:
while True:
if T[j] + K >= T[i+1]:
i = i + 2
j = i
ans += 1
if j == N:
return ans
elif j == N - 1:
ans += 1
return ans
elif T[j] + K < T[i+1]:
i += 1
j = i
ans += 1
if j == N-1:
ans += 1
return ans
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j >= N-1:
return(ans)
break
else:
i += 1
if (i+1) == N-1:
ans += 1
return(ans)
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans += 1
if j == N-1:
ans += 1
return(ans)
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main())
|
s623007047 | p03785 | u810787773 | 1591671930 | Python | Python (3.4.3) | py | Runtime Error | 249 | 7412 | 1826 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
T.sort()
if len(T) == 1:
ans = 1
return(ans)
if C == 1:
return(N)
if C == 2:
while True:
if T[j] + K >= T[i+1]:
i = i + 2
j = i
ans += 1
if j == N + 1:
return ans
elif j == N:
ans += 1
return ans
elif T[j] + K < T[i+1]:
i += 1
j = i
ans += 1
if j == N-1:
ans += 1
return ans
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j >= N-1:
return(ans)
break
else:
i += 1
if (i+1) == N-1:
ans += 1
return(ans)
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans += 1
if j == N-1:
ans += 1
return(ans)
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main())
|
s264497530 | p03785 | u810787773 | 1591671066 | Python | Python (3.4.3) | py | Runtime Error | 244 | 7412 | 1302 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
T.sort()
if len(T) == 1:
ans = 1
return(ans)
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j >= N-1:
return(ans)
break
else:
i += 1
if (i+1) == N-1:
ans += 1
return(ans)
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans += 1
if j == N-1:
ans += 1
return(ans)
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main())
|
s002343163 | p03785 | u810787773 | 1591671043 | Python | Python (3.4.3) | py | Runtime Error | 243 | 7412 | 1303 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
T.sort()
if len(T) == 1:
ans = 1
return(ans)
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j >= N-1:
return(ans)
break
else:
i += 1
if (i+1) == N-1:
ans += 1
return(ans)
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans += 1
if j == N-1:
ans += 1
return(ans)
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main())
|
s660909208 | p03785 | u810787773 | 1591670830 | Python | Python (3.4.3) | py | Runtime Error | 239 | 7520 | 1182 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
T.sort()
if len(T) == 1:
ans = 1
return(ans)
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j >= N-1:
return(ans)
break
else:
i += 1
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans += 1
if j == N-1:
ans += 1
return(ans)
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main())
|
s843803206 | p03785 | u810787773 | 1591670334 | Python | Python (3.4.3) | py | Runtime Error | 244 | 7512 | 1079 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
T.sort()
if len(T) == 1:
ans = 1
return(ans)
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j >= N-1:
return(ans)
break
else:
i += 1
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans = 1
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main())
|
s922412180 | p03785 | u810787773 | 1591670267 | Python | Python (3.4.3) | py | Runtime Error | 249 | 7512 | 1023 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
T.sort()
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j >= N-1:
return(ans)
break
else:
i += 1
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans = 1
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main())
|
s046187001 | p03785 | u810787773 | 1591669979 | Python | Python (3.4.3) | py | Runtime Error | 202 | 7072 | 1009 | def main():
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
ans = 0
i = 0
j = 0
while True:
if T[j] + K >= T[i+1]:
i = i + 1
if i == N-1:
ans += 1
return (ans)
for h in range(C-2):
if T[j] + K >= T[i+1]:
if h == C-3:
ans += 1
i += 2
j = i
if j >= N-1:
return(ans)
break
else:
i += 1
continue
elif T[j] + K < T[i + 1]:
j = i + 1
i = i + 1
ans = 1
break
elif T[j] + K < T[i+1]:
ans += 1
i += 1
j = i
if j == N-1:
ans += 1
return(ans)
print(main()) |
s971544944 | p03785 | u346395915 | 1590848610 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3828 | 767 | n, c, k = map(int, input().split())
check = [0] * (n+10)
for i in range(n):
check[int(input())] += 1
wait = False
time_cnt = 0
people_cnt = 0
ans = 0
for i in range(len(check)):
if wait == False:
if check[i] > 0:
wait = True
people_cnt += check[i]
time_cnt = 1
continue
else:
continue
if people_cnt > c:
ans += people_cnt//c
people_cnt = people_cnt%c
time_cnt = 1
if time_cnt > k:
ans += 1
people_cnt = 0
time_cnt = 0
wait = False
people_cnt += check[i]
time_cnt += 1
else:
if people_cnt > 0:
ans += people_cnt//c
if people_cnt%c > 0:
ans += 1
print(ans) |
s283041800 | p03785 | u346395915 | 1590848335 | Python | PyPy3 (2.4.0) | py | Runtime Error | 501 | 50008 | 786 | n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
check = [0] * (n+10)
for i in t:
check[i] += 1
wait = False
time_cnt = 0
people_cnt = 0
ans = 0
for i in range(len(check)):
if wait == False:
if check[i] > 0:
wait = True
people_cnt += check[i]
time_cnt = 1
continue
else:
continue
if people_cnt > c:
ans += people_cnt//c
people_cnt = people_cnt%c
time_cnt = 1
if time_cnt > k:
ans += 1
people_cnt = 0
time_cnt = 0
wait = False
people_cnt += check[i]
time_cnt += 1
else:
if people_cnt > 0:
ans += people_cnt//c
if people_cnt%c > 0:
ans += 1
print(ans) |
s550248133 | p03785 | u346395915 | 1590847955 | Python | Python (3.4.3) | py | Runtime Error | 174 | 7836 | 786 | n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
check = [0] * (n+10)
for i in t:
check[i] += 1
wait = False
time_cnt = 0
people_cnt = 0
ans = 0
for i in range(len(check)):
if wait == False:
if check[i] > 0:
wait = True
people_cnt += check[i]
time_cnt = 1
continue
else:
continue
if people_cnt > c:
ans += people_cnt//c
people_cnt = people_cnt%c
time_cnt = 1
if time_cnt > k:
ans += 1
people_cnt = 0
time_cnt = 0
wait = False
people_cnt += check[i]
time_cnt += 1
else:
if people_cnt > 0:
ans += people_cnt//c
if people_cnt%c > 0:
ans += 1
print(ans) |
s543842657 | p03785 | u314089899 | 1590714896 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 695 | from collections import deque
N,C,K = map(int, input().split())
T_list = list() #左がもっとも早く着いた人
for i in range(N):
T = int(input())
T_list.append(T)
T_list.sort(reverse=False)
waiting_deque = deque(T_list)
ans = 0
while 1:
if len(waiting_deque) != 0:
ans += 1
bus_passenger = list()
bus_passenger.append(waiting_deque.popleft())
while 1:
if len(waiting_deque)!=0 and len(bus_passenger) < C and bus_passenger[0] + K => waiting_deque[0]:
bus_passenger.append(waiting_deque.popleft())
else:
#print(bus_passenger)
break
else:
break
print(ans) |
s675644348 | p03785 | u230117534 | 1590548343 | Python | Python (3.4.3) | py | Runtime Error | 288 | 8280 | 445 | N, C, K = map(int, input().strip().split(" "))
t = sorted([int(input().strip()) for _ in range(N)])
bus = 0
idx = 0
while idx < N:
bus_go = t[idx] + K
tmp = 0
while idx < N:
if t[idx] <= bus_go:
tmp += 1
idx += 1
if tmp == C:
bus += 1
bus_go = t[idx] + K
tmp = 0
else:
break
if tmp > 0:
bus += 1
print(bus) |
s313897116 | p03785 | u858670323 | 1590233981 | Python | Python (3.4.3) | py | Runtime Error | 184 | 7072 | 309 | n,c,k = map(int,input().split())
t = []
for i in range(n):
t.append(int(input()))
sort(t)
ans = 0
now = 0
ter = -1
for i in range(n):
if ter < t[i]+k:
ans+=1
ter = t[i]+k
now = 1
else:
if(c>=now):
ans+=1
ter = t[i]+k
now = 1
else:
now += 1
print(ans) |
s597581617 | p03785 | u001769145 | 1590121988 | Python | Python (3.4.3) | py | Runtime Error | 611 | 8120 | 464 | # AGC011 A Airport Bus
import bisect
from collections import deque
n, c, k = map(int, input().split())
t_list = [int(input()) for _ in range(n)]
t_list.sort()
t_list = deque(t_list)
ans = 0
while len(t_list) > 0:
_tmp = t_list.popleft() + k
_idx = bisect.bisect_right(t_list, _tmp)
if c <= _idx + 1:
for _ in range(c):
t_list.popleft()
else:
for _ in range(_idx):
t_list.popleft()
ans += 1
print(ans) |
s624663961 | p03785 | u940139461 | 1589833930 | Python | PyPy3 (2.4.0) | py | Runtime Error | 541 | 50520 | 487 | # https://atcoder.jp/contests/agc011/tasks/agc011_a
n, c, k = map(int, input().split())
schedule = []
for _ in range(n):
t = int(input())
schedule.append(t)
schedule.sort()
ans = 0
start = schedule[0]
p = 0
for i in range(n):
s = schedule[i]
if s <= start + k:
p += 1
if p == c:
ans += 1
p = 0
start = schedule[i + 1]
else:
ans += 1
start = schedule[i]
p = 1
if p:
ans += 1
print(ans) |
s052263143 | p03785 | u940139461 | 1589833435 | Python | PyPy3 (2.4.0) | py | Runtime Error | 589 | 51032 | 916 | # https://atcoder.jp/contests/agc011/tasks/agc011_a
n, c, k = map(int, input().split())
schedule = []
for _ in range(n):
t = int(input())
schedule.append(t)
schedule.sort()
# schedule.append(float('inf'))
def check(num, schedule, c, k):
bus = 0
start = schedule[0]
p = 0
i = 0
while i < len(schedule):
s = schedule[i]
if s <= start + k:
p += 1
i += 1
if p == c:
bus += 1
p = 0
start = schedule[i]
else:
start = schedule[i]
bus += 1
p = 1
i += 1
if p:
bus += 1
if bus <= num:
return True
return False
l = 0
r = 10 ** 10
ans = float('inf')
while l <= r:
mid = (l + r) // 2
if check(mid, schedule, c, k):
r = mid - 1
ans = min(ans, mid)
else:
l = mid + 1
print(ans)
|
s298920299 | p03785 | u711238850 | 1589718978 | Python | PyPy3 (2.4.0) | py | Runtime Error | 512 | 50264 | 399 | from math import ceil
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()
bus = 0
bus_time = T[0] + K
tmp_bus = 1
for i in range(1,N):
if T[i] > bus_time:
bus += 1
bus_time = T[i+1] + K
tmp_bus = 0
else:
tmp_bus += 1
if tmp_bus == C:
bus += 1
bus_time = T[i+1] + K
tmp_bus = 0
print(bus+1) |
s172422973 | p03785 | u869917163 | 1589667043 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 280 | N,C,K = map(int,input().split())
A = []
for _ in range(N):
A.append(int(input()))
A.sort()
A0 = A[0]
lis = []
cnt = 0
for i,name enumerate(A):
if name <= A0 + K and len(lis) < C:
lis.append(name)
if len(lis) == C or i == N:
lis.clear()
cnt += 1
print(cnt) |
s872984921 | p03785 | u487594898 | 1589477576 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 427 | input = sys.stdin.readline
n,c,k = map(int,input().split())
A = [int(input()) for i in range(n)]
a = sorted(A)
ans = 0
time = 0.1
num = 0
for i in range(n):
if ans == 0:
ans +=1
time = a[0] -0.1
num +=1
elif ans != 0 and a[i] < time +k and num < c :
num +=1
elif ans != 0 and (c <=num or time +k <=a[i]):
time = a[i] -0.1
num = 1
ans +=1
print(ans) |
s808761309 | p03785 | u321035578 | 1588853734 | Python | Python (3.4.3) | py | Runtime Error | 313 | 7744 | 717 | from collections import deque
n,c,k = map(int,input().split())
t = []
for _ in range(n):
tt = int(input())
t.append(tt)
t.sort()
ans = deque([])
cnt = 0
for i, tt in enumerate(t):
if i == 0:
ans.append([tt+k,1])
cnt += 1
else:
flg = False
for i in range(len(ans)):
tmp = ans.popleft()
if tmp[0] < tt or tmp[1] == c:
continue
else:
flg = True
break
if flg :
tmp[1] += 1
if tmp[1] != c:
a.append(tmp)
ans.appendleft(tmp)
else:
tmp = [tt+k,1]
ans.append(tmp)
cnt += 1
print(cnt)
|
s944553736 | p03785 | u549161102 | 1588505580 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 496 | N,C,K = map(int, input().split())
T = []
for i in range(N):
S.append(input())
S.sort()
st = 0
fi = 1
count = 0
for i in range(N):
a = S[i]
if S[i] ==
while S[fi]-S[st] <= K and fi-st-1 <= C:
fi += 1
else:
count += 1
st = fi + 1
fi = fi + 1
print(count)
N,C,K = map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()
st = 0
fi = 1
count = 0
while S[fi]-S[st] <= K and int(fi)-int(st)-1 <= C:
fi += 1
else:
count += 1
st = fi + 1
fi = fi + 1
print(count) |
s747302864 | p03785 | u411203878 | 1587556623 | Python | PyPy3 (2.4.0) | py | Runtime Error | 513 | 50776 | 421 | n,c,k = map(int,input().split())
ab = []
for _ in range(n):
t=int(input())
ab.append(t)
ab.sort()
bus = 1
bustime = ab[0] + k
customer = 1
for i in range(1,n):
if ab[i] <= bustime:
customer += 1
if customer == c:
bustime = ab[i+i]+k
customer = 0
bus += 1
elif bustime < ab[i]:
bustime = ab[i]+k
customer = 1
bus += 1
print(bus) |
s400511725 | p03785 | u479638406 | 1586361065 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 8344 | 335 | import copy
n, c, k = map(int, input().split())
t = [int(i) for i in range(n)]
t.sort()
s = copy.copy(t)
ans = 0
for i in range(n):
cnt = 1
for j in range(i+1, n):
if t[j] - t[i] <= k:
cnt += 1
t.remove(t[j])
if cnt == c:
ans += 1
break
else:
ans += 1
break
print(ans) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.