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
s743886120
p03779
u450339194
1561430957
Python
Python (3.4.3)
py
Runtime Error
17
3064
307
INF = float("inf") nl = lambda: list(map(int, input().split())) sl = lambda: input().split() n = lambda: int(input()) s = lambda: input() X = n() dp = [0] * (X+1) dp[1] = 1 for i in range(2, X+1): if dp[i - dp[i-1]] < dp[i-1]: dp[i] = dp[i-1] else: dp[i] = dp[i-1]+1 print(dp[X])
s299108132
p03779
u534953209
1559261767
Python
Python (3.4.3)
py
Runtime Error
17
2940
75
X = int(input()) i = 0 sum = 0 while sum < X: i += 1 sum += i print(i)
s405332992
p03779
u502389123
1558713605
Python
Python (3.4.3)
py
Runtime Error
17
2940
101
X = int(input()) sum = 0 for i in range(1, N): sum += i if sum >= X: break print(i)
s450800340
p03779
u623819879
1558240009
Python
PyPy3 (2.4.0)
py
Runtime Error
183
38384
85
x=int(input()) for i in range(x**0.5+100): if i*(i+1)//2>=x: print(i) break
s373457737
p03779
u091051505
1555884384
Python
Python (3.4.3)
py
Runtime Error
18
3060
170
import bisect x = int(input()) num_list = list(range(x)) a = [0]*x a[0] = num_list[0] for i in range(1,x): a[i] = a[i-1] + num_list[i] print(bisect.bisect_left(a, x))
s780785264
p03779
u159994501
1555710832
Python
Python (3.4.3)
py
Runtime Error
74
3928
210
def an(a, b): # a is time b is place if a > b: return float('INF') elif a == b: return a else: return min(an(a + 1, b), an(a + 1, b - a)) X = int(input()) print(an(1, X))
s584353770
p03779
u844646164
1555021068
Python
Python (3.4.3)
py
Runtime Error
17
3064
348
import sys f = open('ABC.txt', 'r') sys.stdin = f import bisect n = int(input()) x = 0 i = 1 x_list = [] while x <= n: x += i if x > n: break x_list.append(x) i += 1 if n == 2: print(2) else: if n in x_list: print(x_list.index(n)+1)""" else: idx = bisect.bisect_left(x_list, n) idx -= 2 print(n-x_list[idx])"""
s703539923
p03779
u091051505
1554348187
Python
Python (3.4.3)
py
Runtime Error
18
3188
170
import bisect x = int(input()) num_list = list(range(x)) a = [0]*x a[0] = num_list[0] for i in range(1,x): a[i] = a[i-1] + num_list[i] print(bisect.bisect_left(a, x))
s257733492
p03779
u091051505
1554347717
Python
Python (3.4.3)
py
Runtime Error
21
3060
170
import bisect x = int(input()) num_list = list(range(x)) a = [0]*x a[0] = num_list[0] for i in range(1,x): a[i] = a[i-1] + num_list[i] print(bisect.bisect_left(a, x))
s131582167
p03779
u785578220
1548365430
Python
Python (3.4.3)
py
Runtime Error
18
2940
149
a = int(input()) s = 0 if i < 3:print(a) else: for i in range(1,a): s+=i if s-i < a <= s: print(i) break
s557080328
p03779
u513081876
1546133115
Python
Python (3.4.3)
py
Runtime Error
18
2940
102
X = int(input()) for i in range(1, 10**6): if X <= 0.5 * i (i + 1): print(i) break
s547607864
p03779
u944209426
1535630494
Python
Python (3.4.3)
py
Runtime Error
17
3060
148
x=int(input()) n=int((2*int(input()))**0.5) if n*(n-1)<2*x<=n*(n+1): print(n) elif (n-1)*(n-2)<2*x<=n*(n-1): print(n-1) else: print(n+1)
s074698754
p03779
u807772568
1534263127
Python
Python (3.4.3)
py
Runtime Error
18
2940
124
a = int(input()) i = 1 j = 0 ans = 0 while True: ans += 1 j += i i += 1 if j >= a: print(ans) break
s387055589
p03779
u333945892
1532479188
Python
Python (3.4.3)
py
Runtime Error
17
2940
103
X = int(input()) N = int(math.sqrt(2*X))-1 while True: if N*(N+1)//2 >= X: print(N) break N += 1
s813568988
p03779
u226746496
1529109294
Python
Python (3.4.3)
py
Runtime Error
17
3064
112
X = int(input()) for i in range(0, X): result += (i+1) if X >= result: print(i+1) break
s582123504
p03779
u925364229
1518303482
Python
Python (3.4.3)
py
Runtime Error
25
2940
110
X = int(input()) sumval = 0 for i in range(1,X): sumval += i if sumval >= X: ans = i break print(ans)
s214544994
p03779
u943004959
1516302835
Python
Python (3.4.3)
py
Runtime Error
19
3060
360
from bisect import bisect_left, bisect_right, insort_left, insort_right def solve(): x = int(input()) cumulative_sum = [(k * (k - 1)) // 2 for k in range(1, 46)] target = bisect_left(cumulative_sum, x) if x in cumulative_sum: print(cumulative_sum.index(x)) else: print(target - 1 + (x - cumulative_sum[target])) solve()
s327457241
p03779
u813450984
1515452239
Python
Python (3.4.3)
py
Runtime Error
18
2940
109
def f(n, l): sum = 0 for i in range(1, n+1): sum += i if sum >= n: return i print(f(n, l))
s973563923
p03779
u495415554
1511844140
Python
Python (3.4.3)
py
Runtime Error
17
2940
92
https://www.lifehacker.jp/2017/11/171127_kakei_17.html?utm_source=dlvr.it&utm_medium=twitter
s730644991
p03779
u817328209
1499239581
Python
Python (3.4.3)
py
Runtime Error
17
2940
137
X = int(input()) L = 0 for t in range(1, X) : L += t if L >= X : print(t) break
s586258331
p03779
u817328209
1499239020
Python
Python (3.4.3)
py
Runtime Error
17
2940
74
X = int(input()) L = 0 for i in range(1, X) : L += i if L >= X :
s237809265
p03779
u351527281
1497580786
Python
Python (3.4.3)
py
Runtime Error
18
3060
148
num = int(input()) i = 1 while True: bef = range(1,i) i += 1 aft = range(1,i) if bef < num <= aft: print(i-1) break
s348022778
p03779
u351527281
1497580682
Python
Python (3.4.3)
py
Runtime Error
17
2940
147
num = int(input()) i = 0 while True: bef = range(1,i) i += 1 aft = range(1,i) if bef < num <= aft: print(i-1) break
s555814402
p03779
u939822134
1492196579
Python
Python (3.4.3)
py
Runtime Error
31
2940
143
import sys X = int(input()) if X == 1: print(1) elif X > 1: for i in range(2,1000000000): if X <= i*(i + 1)/2: t = i break print(i)
s207419522
p03779
u939822134
1492187018
Python
Python (3.4.3)
py
Runtime Error
32
2940
141
import sys X = int(input()) if X == 1: print(1) elif X > 1: for i in range(2,100000): if X <= i*(i + 1)/2: t = i break print(i)
s633310934
p03779
u026450699
1491350353
Python
Python (2.7.6)
py
Runtime Error
11
2568
359
X = int(raw_input()) def makeValue(x, n): if(n == 0): return False if(x == n): return True if(x == -n): return True if(makeValue(x - n, n - 1)): return True if(makeValue(x + n, n - 1)): return True return False for i in range(1, X + 1): if(makeValue(X, i)): print i break
s614637677
p03779
u775600206
1491194649
Python
Python (2.7.6)
py
Runtime Error
10
2568
101
# -*- coding: utf-8 -*- X= int(raw_input().split()) a = 0 while X >0: a += 1 X -= a print a
s004503184
p03779
u775600206
1491194571
Python
Python (2.7.6)
py
Runtime Error
10
2568
105
# -*- coding: utf-8 -*- X= map(int,raw_input().split()) a = 0 while X >0: a += 1 X -= a print a
s780035138
p03779
u732844340
1489981740
Python
Python (3.4.3)
py
Runtime Error
73
4036
304
y = [] x = 0 def slv(h, i): if x == h or i >= x: if x == h: y.append(i - 1) return slv(h+i, i+1) # jump slv(h, i+1) # stay if __name__ == '__main__': x = abs(int(input())) slv(0, 0) if len(y) == 0: print(2) else: print(min(y))
s794608992
p03779
u732844340
1489980888
Python
Python (3.4.3)
py
Runtime Error
75
3976
299
y = [] def slv(x,h,i): if x == h or i >= x: if x == h: y.append(i) return slv(x,h+i,i+1) # jump slv(x,h,i+1) # stay if __name__ == '__main__': x = int(input()) slv(abs(x),0,0) if len(y) == 0: print(2) else: print(min(y) - 1)
s110556744
p03779
u732844340
1489980731
Python
Python (3.4.3)
py
Runtime Error
78
3952
2324
y = [] def slv(x,h,i): if x == h or i >= x: if x == h: y.append(i) return slv(x,h+i,i+1) # jump slv(x,h,i+1) # stay if __name__ == '__main__': x = int(input()) slv(abs(x),0,0) print(y) if len(y) == 0: print(2) else: print(min(y) - 1)
s777535457
p03779
u181709987
1489962476
Python
Python (3.4.3)
py
Runtime Error
18
3060
217
import math X = int(input()) n = math.sqrt(2*X) -1 def sum(a): x = 0 for i in range(a+1): x += i return x for i in range(n,X+1): if sum(i)>= X: result = i break print(result)
s726296909
p03779
u762603420
1489891463
Python
Python (2.7.6)
py
Runtime Error
28
3556
331
# -*- coding: utf-8 -*- def check(t, n, idx): if t == n + idx or t == n - idx: return idx if idx >= t and t > 0: return t elif t < 0 and idx * -1 <= t: return idx return min(check(t, n + idx, idx + 1), check(t, n - idx, idx + 1), check(t, n, idx + 1)) X = int(input()) print(check(X, 0, 1))
s942067376
p03779
u846552659
1489891150
Python
Python (3.4.3)
py
Runtime Error
76
4080
429
# -*- coding:utf-8 -*- def search(t, x, i): # print('t:'+str(t)+' x:'+str(x)+' i:'+str(i)) global X # print(l) # print('X:'+str(X)) if x == X: #l.append(t) return t elif x > X: ans1 = search(i, x, i+1) ans2 = search(i, x-i, i+1) return min(ans1, ans2) else: ans3 = search(i, x+i, i+1) return ans3 X = int(input()) ans = search(0, 0, 1) print(ans)
s565309695
p03779
u762603420
1489891084
Python
Python (2.7.6)
py
Runtime Error
27
3604
272
# -*- coding: utf-8 -*- def check(t, n, idx): if t == n + idx or t == n - idx: return idx if idx >= t: return t return min(check(t, n + idx, idx + 1), check(t, n - idx, idx + 1), check(t, n, idx + 1)) X = int(raw_input()) print(check(X, 0, 1))
s558518750
p03779
u070154761
1489890624
Python
Python (2.7.6)
py
Runtime Error
10
2568
322
x = int(raw_input()) ans = 0 count = 0 half = x / 2 array = range(x + 1) for i in range(x): if x == 2 or x == 1: break if sum(array) == x: break elif sum(array[:len(array) - 2]) < x: array.pop() break else: array.pop() count += 1 print array[len(array) - 1]
s551398409
p03779
u070154761
1489889965
Python
Python (2.7.6)
py
Runtime Error
10
2568
139
x = int(raw_input()) ans = 0 count = 0 for i in range(x + 1): ans += i if ans >= x: count = i break print count
s737710397
p03779
u112002050
1489889791
Python
Python (3.4.3)
py
Runtime Error
17
3064
143
import math X = int(input()) l = list(range(1,math.ceil(X / 2))) while l: if sum(l) < X: print(len(l)+1) break l.pop()
s615607699
p03779
u622568141
1489888132
Python
Python (3.4.3)
py
Runtime Error
73
3960
230
X = int(input()) def move(i, x): if x == X: return i elif i > X: return X+1 else: if x > X: return min([move(i+1, x-(i+1)), move(i+1, x)]) else: return min([move(i+1, x+(i+1)), move(i+1, x)]) print((move(0,0)))
s605631762
p03779
u762603420
1489888086
Python
Python (2.7.6)
py
Runtime Error
24
3536
355
# -*- coding: utf-8 -*- def check(t, now, idx): if t < idx: return 99999999999 # use use = 999999999999 if t == now + idx: use = idx elif t > now + idx: use = check(t, now + idx, idx + 1) # not use nuse = check(t, now, idx + 1) return min(use, nuse) X = int(raw_input()) print(str(check(X, 0, 1)))
s400336464
p03779
u762603420
1489887864
Python
Python (2.7.6)
py
Runtime Error
23
3536
331
# -*- coding: utf-8 -*- def check(t, now, idx): if t < idx: return 99999999999 # use use = -1 if t == now + idx: use = idx else: use = check(t, now + idx, idx + 1) # not use nuse = check(t, now, idx + 1) return min(use, nuse) X = int(raw_input()) print(str(check(X, 0, 1)))
s776554042
p03779
u239375815
1489886652
Python
Python (3.4.3)
py
Runtime Error
72
4164
172
def move(i=0,cx=0): global m if(cx+i==X): m=min(m,i) elif cx+i<X: move(i+1,cx+i) move(i+1,cx) X=int(input()) m=10**9 move() print(m)
s190968494
p03780
u792078574
1600923502
Python
PyPy3 (7.3.0)
py
Runtime Error
101
68568
1162
from itertools import accumulate import numpy as np def main(): N, K = map(int, input().split()) As = list(map(int, input().split())) dp = np.array([0] * (K+1)) dp[0] = 1 nonzeros = [np.array([0])] for a in As: ndp = np.array([0] * (K+1)) nonzero = [] for i in range(K+1): t = dp[i] if i < a else dp[i] + dp[i-a] if t > 0: nonzero.append(i) ndp[i] = 1 nonzeros.append(np.array(nonzero)) dp = ndp dp = np.array([0] * (K+1)) dp[0] = 1 acc = list(accumulate(dp)) + [0] ans = 0 for i in range(N, 0, -1): a = As[i-1] ndp = np.array([0] * (K+1)) for j in range(K+1): t = dp[j] if j < a else dp[j] + dp[j-a] if t > 0: ndp[i] = 1 dp = ndp if a < K: nonzero = nonzeros[i-1] for y in nonzero: t = K-y-a-1 if acc[K-y-1] > acc[t if t >= 0 else -1]: break else: ans += 1 acc = list(accumulate(dp)) + [0] print(ans) main()
s916191854
p03780
u787059958
1600563385
Python
Python (3.8.2)
py
Runtime Error
2456
144184
1802
def main(): N, K = map(int, input().split()) A = [0] + list(map(int, input().split())) rdp_shift = [N + 1] * K # rdp_shift[j] = (右からi個を使って部分和jを作れるような最初のi) rdp_shift[0] = 0 rdp = [0] * K # rdp[i][j] = (a(-1),...,a(-i)の部分和でjを作れるか) rdp[0] = 1 for i in range(N): rdp2 = [0] * K for j in range(K): if rdp[j] == 1: rdp2[j] = 1 elif (j >= A[-i] and rdp[j - A[-i]] == 1): # print(j - A[i]) rdp2[j] = 1 rdp_shift[j] = i # print(rdp_shift) rdp = rdp2 # print(rdp_shift) ldp = [0] * K # ldp[i][j] = (a1,...,aiの部分和でjを作れるか) ldp[0] = 1 S = [0] * (K + 1) ans = 0 for i in range(1, N + 1): # ここで一つ一つチェックしている!! # A[i]が不要かチェック for j in range(K): S[j + 1] = S[j] # print(N - i, rdp_shift[j]) if rdp_shift[j] <= N - i: print(S, rdp_shift, j, N - i, A[i]) S[j + 1] += 1 no_need = True for lval in range(K): if ldp[lval] == 0: continue # print(K - A[i] - lval) rval = S[K - lval] - S[max(0, K - A[i] - lval)] # print(S, K - lval, K - A[i] - lval, rval) if rval > 0: no_need = False break if no_need: ans += 1 # ldp[i][:]の計算 ldp2 = [0] * K for j in range(K): if ldp[j] == 1 or (j >= A[i] and ldp[j - A[i]] == 1): ldp2[j] = 1 ldp = ldp2 print(ans) # print(S) if __name__ == "__main__": main()
s904850911
p03780
u787059958
1600554618
Python
Python (3.8.2)
py
Runtime Error
428
205548
615
N, K = map(int, input().split()) A = sorted(map(int, input().split())) sum_A = sum(A) if sum_A < K: print(len(A)) exit() elif sum_A == K: print(0) exit() dp = [[False] * len(A) for i in range(len(A))] sum_A_list = [] for i in range(N): if i == 0: sum_A_list.append(A[i]) continue sum_A_list.append(sum_A_list[i - 1] + A[i]) idx = 0 for i in range(N - 1, -1, -1): if sum_A_list[i] < K: idx = i break for i in range(idx + 1): if sum_A_list[idx + 1] - sum_A_list[i] >= K: continue else: idx = i - 1 break print(idx + 1)
s309607244
p03780
u036104576
1598729801
Python
Python (3.8.2)
py
Runtime Error
2206
9848
1341
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N, K = map(int, input().split()) A = list(sorted(map(int, input().split()))) def check(x): if A[x] >= K: return True dp = [False] * (K + 1) dp[0] = True for j, a in enumerate(A): if j == x: continue for i in range(K, 0, -1): if i >= a: dp[i] |= dp[i - a] for i in range(K - x, K): if dp[i]: return True return False left = -1 right = N while right - left > 1: mid = (left + right) // 2 if check(mid): right = mid else: left = mid print(right)
s109505350
p03780
u036104576
1598727325
Python
PyPy3 (7.3.0)
py
Runtime Error
1414
230636
1249
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N, K = map(int, input().split()) A = list(map(int, input().split())) dp = [0] * (K + 1) dp[0] = 1 for a in A: for i in range(K, 0, -1): if i >= a: dp[i] += dp[i - a] ans = 0 for a in A: x = K - a necessary = False for i in range(x, K): if i >= a: if dp[i] - dp[i - a] >= 1: necessary = True else: if dp[i] >= 1: necessary = True if necessary: ans += 1 print(N - ans)
s116819832
p03780
u107639613
1597812142
Python
PyPy3 (7.3.0)
py
Runtime Error
2208
106580
1183
import sys def input(): return sys.stdin.readline().strip() def main(): N, K = map(int, input().split()) A = [0] + list(map(int, input().split())) """ (aが不要なカード)=(A-{a}からK-a以上の最小の部分和を取った時、それがK以上) まで言い換えてドボン。。。 部分和の全列挙しなくても和がKまでで打ち切っていいんだから、ここでdpの発想が出なかったのは切腹。 まずは部分点解法を実装してみる。 """ ans = 0 for k in range(1, N + 1): # dp[i][j] = (i個使って(ただしA[k]を除く)部分和jが作れるか) dp = [1] + [0] * K for i in range(1, N + 1): if i == k: continue dp2 = [0] * (K + 1) for j in range(K + 1): if dp[j] == 1: dp2[j] = 1 dp2[min(K, j + A[i])] = 1 dp = dp2 no_need = True for j in range(K - A[k], K): if dp[j] != 0: no_need = False break if no_need: ans += 1 print(ans) if __name__ == "__main__": main()
s072651500
p03780
u107639613
1597811826
Python
PyPy3 (7.3.0)
py
Runtime Error
2208
107792
1248
import sys from bisect import bisect_left def input(): return sys.stdin.readline().strip() def main(): N, K = map(int, input().split()) A = [0] + list(map(int, input().split())) """ (aが不要なカード)=(A-{a}からK-a以上の最小の部分和を取った時、それがK以上) まで言い換えてドボン。。。 部分和の全列挙しなくても和がKまでで打ち切っていいんだから、ここでdpの発想が出なかったのは切腹。 まずは部分点解法を実装してみる。 """ ans = 0 for k in range(1, N + 1): # dp[i][j] = (i個使って(ただしA[k]を除く)部分和jが作れるか) dp = [1] + [0] * K for i in range(1, N + 1): if i == k: continue dp2 = [0] * (K + 1) dp2[min(K, A[i])] = 1 for j in range(K + 1): if dp[j] == 1: dp2[j] = 1 dp2[min(K, j + A[i])] = 1 dp = dp2 no_need = True for j in range(K - A[k], K): if dp[j] != 0: no_need = False break if no_need: ans += 1 print(ans) if __name__ == "__main__": main()
s352917027
p03780
u074220993
1597608860
Python
Python (3.8.2)
py
Runtime Error
2206
10700
1338
import collections N, K = map(int, input().split()) a = [int(x) for x in input().split() if int(x) < K] a.sort() def renew_dp(dp, List, K): #Listの部分和がiならばdp[i]=True for x in List: dp_ = dp.copy() for i in range(1,K): if i-x < 0: continue if dp[i-x]: dp_[i] = True dp = dp_ return dp def judge(a, dp, K): #aが必要(True)か不必要(False)か for i in range(K-a,K): if dp[i]: return True return False def binary_tree(List, base_List, K): #2分木探索 center = len(List)//2 #2分する支点 dp = {} dp = collections.defaultdict(lambda:False) dp[0] = True List_without_center = base_List.copy() List_without_center.remove(List[center]) dp = renew_dp(dp, List_without_center, K) #centerのdp更新 if len(List) == 1: #2分木のゴール if judge(List[center], dp, K): result = center else: result = center+1 else: #再帰的に探索 if judge(List[center], dp, K): result = binary_tree(List[:center], base_List, K) else: result =binary_tree(List[center:], base_List, K) + center return result ans = binary_tree(a, a, K) #ans以下のjについて、a[j]は不必要 print(ans)
s250092134
p03780
u074220993
1597598138
Python
Python (3.8.2)
py
Runtime Error
2206
45036
853
N, K = map(int, input().split()) a = [int(x) for x in input().split() if int(x)<K] def bfs(List, remain, K): #幅優先探索 over_K = K for x in List: if x == remain: #和がKとなる部分集合を構成できる場合 return 0 for x in List: if over_K == 0: #over_K=0なら即リターン return over_K next_remain = remain -x if next_remain < 0: over_K = min(over_K, -next_remain) else: copy_List = List.copy() copy_List.remove(x) over_K = min(over_K, bfs(copy_List, next_remain, K)) #1段だけ深く探索 return over_K no_need = 0 for x in a: copy_a = a.copy() copy_a.remove(x) result = bfs(copy_a, K-x, K) if result == 0: continue if result - x >= 0: no_need += 1 print(no_need)
s158055254
p03780
u895641117
1597095805
Python
Python (3.8.2)
py
Runtime Error
2211
219652
685
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) ok = n ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 a[mid] ^= a[n - 1] a[n - 1] ^= a[mid] a[mid] ^= a[n - 1] dp = [[False for j in range(k)] for i in range(n)] dp[0][0] = True for i in range(n - 1): for j in range(k): dp[i + 1][j] = dp[i + 1][j] or dp[i][j] if j + a[i] < k: dp[i + 1][j + a[i]] = dp[i + 1][j + a[i]] or dp[i][j] flg = False for j in range(k - a[n - 1], k): if dp[n - 1][j]: flg = True break if flg: ok = mid else: ng = mid print(ok)
s729650551
p03780
u873915460
1595632944
Python
PyPy3 (7.3.0)
py
Runtime Error
111
74860
391
N,K=map(int,input().split()) A=sorted(filter(lambda x:x<K,list(map(int,input().split())))) N=len(A) def judge(x): DP=1 Z=(1<<K)-1 for i in range(N): if i!=x: DP=((DP|(DP<<A[i]))&Z) r=0 for i in range(K-A[x],K): r|=(DP&(1<<i)) return r if judge(0): print(0) exit() L,R,M=1,N,0 while L!=R: M=(L+R)//2 if judge(M)==0: L=max(L+1,M) else: R=M print(L)
s782174089
p03780
u786020649
1595390517
Python
Python (3.8.2)
py
Runtime Error
73
9436
1472
import sys 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 mkns(a,s,m): if a==0: return s else: return (((s+1)<<a)|s) & m def main(): N,K=map(int,sys.stdin.readline().strip().split()) a=list(map(int,sys.stdin.readline().strip().split())) a.sort() ss=[0]*(N+1) pm=(1<<K)-1 mask=lambda c:(1<<K)-(1<<c) nn=0 def isunnec(i): if a[i]>=K: return False for j in range(i+1,N): if a[j]>=K: break ss[i]=(((ss[i]+1)<<a[j])|ss[i]) & pm # print(bin(ss[i]), bin(mask(K-c)),ss[i]&mask(K-c)) if ss[i]&mask(K-a[i])==0: return True return False # for i in range(N): # if a[i]>=K: # break # ss[i+1]=(((ss[i]+1)<<a[i])|ss[i]) & pm # if isunnec(i): # nn+=1 # for j in range(i+1,N): # if a[j]>=K: # break # ss[i]=mkns(a[j],ss[i],pm) # # print(bin(ss[i]), bin(mask(K-c)),ss[i]&mask(K-c)) # if ss[i]&mask(K-a[i])==0: # nn+=1 m=len(list(filter(lambda x:x<K, a))) nn=biser(list(range(m)),isunnec)+1 # print(list(map(bin,ss))) print(nn) if __name__=='__main__': main()
s959919414
p03780
u786020649
1595307761
Python
Python (3.8.2)
py
Runtime Error
2214
313616
1463
import sys 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] 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() ci=list(range(N)) def func(h): c=cards[h] cards[h]=0 ret=findminsum(cards,K-c,N)>=K cards[h]=c return ret #nn=0 nn=biser(ci,func) # 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) if __name__=='__main__': main()
s584133649
p03780
u786020649
1595307108
Python
Python (3.8.2)
py
Runtime Error
2217
314044
1391
import sys sys.setrecursionlimit(10000) def biser(lst,func): n=len(lst) nh=n//2 if n==1: return lst[0] if func(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] 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() ci=list(range(N)) def func(h): c=cards[h] cards[h]=0 ret=findminsum(cards,K-c,N)>=K cards[h]=c return ret #nn=0 nn=biser(ci,func) # 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) if __name__=='__main__': main()
s616810890
p03780
u786020649
1595306925
Python
Python (3.8.2)
py
Runtime Error
2213
314456
1361
import sys def biser(lst,func): n=len(lst) nh=n//2 if n==1: return lst[0] if func(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] 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() ci=list(range(N)) def func(h): c=cards[h] cards[h]=0 ret=findminsum(cards,K-c,N)>=K cards[h]=c return ret #nn=0 nn=biser(ci,func) # 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) if __name__=='__main__': main()
s076228924
p03780
u786020649
1595303381
Python
Python (3.8.2)
py
Runtime Error
26
9096
984
import sys def findminsum(lst,K,N,dp): 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(): inf=10**6 dp=[[inf]*N for s in range(K+1)] 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)) cards.sort() N=len(cards) nn=0 for i in range(N): if cards[i]<K: c=cards[i] cards[i]=0 if findminsum(cards,K-c,N,dp)>=K: nn+=1 cards[i]=c else: break print(nn) if __name__=='__main__': main()
s363538031
p03780
u786020649
1595300166
Python
Python (3.8.2)
py
Runtime Error
388
204960
917
import sys def findminsum(lst,K,N): inf=10**10 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]: ds[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.sort() nn=0 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) if __name__=='__main__': main()
s615384881
p03780
u786020649
1595300122
Python
Python (3.8.2)
py
Runtime Error
27
8896
916
import sys def findminsum(lst,K,N): inf=10**10 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] ds[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.sort() nn=0 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) if __name__=='__main__': main()
s633754127
p03780
u893063840
1595084544
Python
Python (3.8.2)
py
Runtime Error
2210
156484
854
import numpy as np from numba import njit n, k = map(int, input().split()) a = tuple(map(int, input().split())) dp = np.zeros((n + 1, k), bool) dp[0][0] = True for i, e in enumerate(a, 1): dp[i] = dp[i-1] dp[i, e:] |= dp[i-1, :-e] dp2 = np.zeros((n + 1, k), bool) dp2[0][0] = True for i, e in enumerate(a[::-1], 1): dp2[i] = dp2[i-1] dp2[i, e:] |= dp2[i-1, :-e] @njit def f(a, dp, dp2): ret = 0 for i, e in enumerate(a, 1): li = [j for j in range(k) if dp[i-1][j]] li2 = [j for j in range(k) if dp2[n-i][j]] j = len(li2) - 1 mx = 0 for e2 in li: while j > 0 and e2 + li2[j] >= k: j -= 1 if e2 + li2[j] < k: mx = max(mx, e2 + li2[j]) if mx + e < k: ret += 1 return ret ans = f(a, dp, dp2) print(ans)
s916073188
p03780
u893063840
1595083727
Python
Python (3.8.2)
py
Runtime Error
2209
187364
1088
from numba import njit @njit def solve(n, k, a): dp = [[0] * k for _ in range(n + 1)] dp[0][0] = 1 for i, e in enumerate(a, 1): for j in range(k): dp[i][j] = dp[i-1][j] for j in range(k - e): if dp[i-1][j]: dp[i][j+e] = 1 dp2 = [[0] * k for _ in range(n + 1)] dp2[0][0] = 1 for i, e in enumerate(a[::-1], 1): for j in range(k): dp2[i][j] = dp2[i-1][j] for j in range(k - e): if dp2[i-1][j]: dp2[i][j+e] = 1 ans = 0 for i, e in enumerate(a, 1): li = [j for j in range(k) if dp[i-1][j]] li2 = [j for j in range(k) if dp2[n-i][j]] j = len(li2) - 1 mx = 0 for e2 in li: while j > 0 and e2 + li2[j] >= k: j -= 1 if e2 + li2[j] < k: mx = max(mx, e2 + li2[j]) if mx + e < k: ans += 1 print(ans) if __name__ == "__main__": n, k = map(int, input().split()) a = tuple(map(int, input().split())) solve(n, k, a)
s129914045
p03780
u047796752
1594179628
Python
PyPy3 (7.3.0)
py
Runtime Error
2247
1275964
715
import sys input = sys.stdin.readline def judge(x): b = [a[i] for i in range(N) if i!=x] dp = [[0]*K for _ in range(N)] dp[0][0] = 1 for i in range(N-1): for j in range(K): dp[i+1][j] += dp[i][j] if j+b[i]<K: dp[i+1][j+b[i]] += dp[i][j] for i in range(K-x, K): if dp[N-1][i]>0: return False return True def binary_search(): l, r = 0, N-1 while l<=r: m = (l+r)//2 if judge(m): l = m+1 else: r = m-1 return r N, K = map(int, input().split()) a = list(map(int, input().split())) a.sort() print(binary_search()+1)
s238829741
p03780
u144913062
1591305628
Python
PyPy3 (2.4.0)
py
Runtime Error
169
38384
1144
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; vector<int> a(N); REP(i, N) cin >> a[i]; vector<vector<int>> dp_left(N+1, vector<int>(K)); vector<vector<int>> dp_right(N+1, vector<int>(K)); dp_left[0][0] = dp_right[N][0] = 1; REP(i, N) { REP(j, K) { dp_left[i+1][j] = dp_left[i][j]; if (j >= a[i]) dp_left[i+1][j] |= dp_left[i][j-a[i]]; dp_right[N-i-1][j] = dp_right[N-i][j]; if (j >= a[N-i-1]) dp_right[N-i-1][j] |= dp_right[N-i][j-a[N-i-1]]; } } int ans = 0; REP(i, N) { vector<int> cum(K+1); REP(j, K) cum[j+1] = cum[j] + dp_right[i+1][j]; bool ok = true; REP(j, K) { if (!dp_left[i][j]) continue; if (cum[K-j] - cum[max(0, K-a[i]-j)] > 0) { ok = false; break; } } if (ok) ans++; } cout << ans << endl; }
s858912470
p03780
u368796742
1590947181
Python
PyPy3 (2.4.0)
py
Runtime Error
2135
490632
928
n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() if a[0] >= k: print(0) exit() if sum(a) < k: print(n) exit() def search(m): if m >= k: return True x = k-a[m] dp = [[float("INF")]*(x+1) for i in range(n)] dp[0][0] = 0 now = 0 for i in range(n): if i == m: continue for j in range(x+1): if dp[now][j] !=float("INF"): dp[now+1][j] = min(dp[now][j],dp[now+1][j]) if a[i]+j < x: dp[now+1][a[i]+j] = a[i]+j else: dp[now+1][-1] = min(a[i]+j,dp[now+1][-1]) now += 1 if dp[-1][-1] == float("INF"): return True elif dp[-1][-1] >= k: return False else: return True le = 0 ri = n while ri > le+1: m = (ri+le)//2 if search(m): ri = m else: le = m print(le+1)
s797779768
p03780
u368796742
1590946168
Python
PyPy3 (2.4.0)
py
Runtime Error
2136
529032
833
n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() if a[0] >= k: print(0) exit() def search(m): if m >= k: return True x = k-a[m] dp = [[float("INF")]*(x+1) for i in range(n)] dp[0][0] = 0 now = 0 for i in range(n): if i == m: continue for j in range(x+1): if dp[now][j] !=float("INF"): dp[now+1][j] = min(dp[now][j],dp[now+1][j]) if a[i]+j < x: dp[now+1][a[i]+j] == a[i]+j else: dp[now+1][-1] = min(a[i]+j,dp[now+1][-1]) now += 1 if dp[-1][-1] >= k: return False else: return True le = 0 ri = n while ri > le+1: m = (ri+le)//2 if search(m): ri = m else: le = m print(le+1)
s977871764
p03780
u368796742
1590946097
Python
PyPy3 (2.4.0)
py
Runtime Error
2146
523016
834
n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() if a[0] >= k: print(0) exit() def search(m): if m >= k: return True x = k-a[m] dp = [[float("INF")]*(x+1) for i in range(n)] dp[0][0] = 0 now = 0 for i in range(n): if i == m: continue for j in range(x+1): if dp[now][j] !=float("INF"): dp[now+1][j] = min(dp[now][j],dp[now+1][j]) if a[i]+j < x: dp[now+1][a[i]+j] == a[i]+j else: dp[now+1][-1] = min(a[i]+j,dp[now+1][-1]) now += 1 if dp[-1][-1] >= k: return False else: return True le = -1 ri = n while ri > le+1: m = (ri+le)//2 if search(m): ri = m else: le = m print(le+1)
s035676346
p03780
u368796742
1590946029
Python
PyPy3 (2.4.0)
py
Runtime Error
2139
513160
797
n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() def search(m): if m >= k: return True x = k-a[m] dp = [[float("INF")]*(x+1) for i in range(n)] dp[0][0] = 0 now = 0 for i in range(n): if i == m: continue for j in range(x+1): if dp[now][j] !=float("INF"): dp[now+1][j] = min(dp[now][j],dp[now+1][j]) if a[i]+j < x: dp[now+1][a[i]+j] == a[i]+j else: dp[now+1][-1] = min(a[i]+j,dp[now+1][-1]) now += 1 if dp[-1][-1] >= k: return False else: return True le = -1 ri = n while ri > le+1: m = (ri+le)//2 if search(m): ri = m else: le = m print(le+1)
s049605204
p03780
u368796742
1590945895
Python
PyPy3 (2.4.0)
py
Runtime Error
2134
476936
838
n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() if sum(a) < k: print(n) exit() def search(m): if m >= k: return True x = k-a[m] dp = [[float("INF")]*(x+1) for i in range(n)] dp[0][0] = 0 now = 0 for i in range(n): if i == m: continue for j in range(x+1): if dp[now][j] !=float("INF"): dp[now+1][j] = min(dp[now][j],dp[now+1][j]) if a[i]+j < x: dp[now+1][a[i]+j] == a[i]+j else: dp[now+1][-1] = min(a[i]+j,dp[now+1][-1]) now += 1 if dp[-1][-1] >= k: return False else: return True le = -1 ri = n+1 while ri > le+1: m = (ri+le)//2 if search(m): ri = m else: le = m print(le+1)
s095013842
p03780
u519923151
1589480453
Python
Python (3.4.3)
py
Runtime Error
2117
213748
631
n,k = map(int, input().split()) al = list(map(int, input().split())) if sum(al) < k: print(n) exit() res = 0 for h in range(n): dp=[[0 for i in range(k)] for j in range(n)] dp[0][0]=1 judge =0 newal = sorted(al) xk = k-newal[h] newal.pop(h) for i in range(n-1): for j in range(k): if newal[i]<=j: #i+1番目の数字a[i]を足せるかも dp[i+1][j]=dp[i][j-newal[i]] or dp[i][j] else: #入る可能性はない dp[i+1][j]=dp[i][j] for l in range(xk,k): if dp[n-1][l] ==1: print(n-h-1) exit()
s937928634
p03780
u519923151
1589480312
Python
Python (3.4.3)
py
Runtime Error
2117
213748
623
n,k = map(int, input().split()) al = list(map(int, input().split())) if sum(al) < k: print(n) exit() dp=[[0 for i in range(k)] for j in range(n)] dp[0][0]=1 res = 0 for h in range(n): judge =0 newal = sorted(al) xk = k-newal[h] newal.pop(h) for i in range(n-1): for j in range(k): if newal[i]<=j: #i+1番目の数字a[i]を足せるかも dp[i+1][j]=dp[i][j-newal[i]] or dp[i][j] else: #入る可能性はない dp[i+1][j]=dp[i][j] for l in range(xk,k): if dp[n-1][l] ==1: print(n-h-1) exit()
s775040780
p03780
u519923151
1589480231
Python
Python (3.4.3)
py
Runtime Error
2117
213736
621
n,k = map(int, input().split()) al = list(map(int, input().split())) if sum(al) < k: print(n) exit() dp=[[0 for i in range(k)] for j in range(n)] dp[0][0]=1 res = 0 for h in range(n): judge =0 newal = sorted(al) xk = k-newal[h] newal.pop(h) for i in range(n-1): for j in range(k): if newal[i]<=j: #i+1番目の数字a[i]を足せるかも dp[i+1][j]=dp[i][j-newal[i]] or dp[i][j] else: #入る可能性はない dp[i+1][j]=dp[i][j] for l in range(xk,k): if dp[n-1][l] ==1: print(n-h) exit()
s187436218
p03780
u519923151
1589479007
Python
Python (3.4.3)
py
Runtime Error
2129
414452
900
n,k = map(int, input().split()) al = list(map(int, input().split())) if sum(al) < k: print(n) exit() newal = sorted(al) for m in range(n): if newal[m] >k: cut = m al = newal[:cut] break n = len(al) dp=[[0 for i in range(k*2)] for j in range(n)] dp[0][0]=1 res = 0 for h in range(n): judge =0 newal = sorted(al) xk = k-newal[h] newal.pop(h) for i in range(n-1): for j in range(k*2): if newal[i]<=j: #i+1番目の数字a[i]を足せるかも dp[i+1][j]=dp[i][j-newal[i]] or dp[i][j] else: #入る可能性はない dp[i+1][j]=dp[i][j] for l in range(xk,k*2): if judge ==1: break if dp[n-1][l] ==1: mins = l if l >=k: res += 1 judge = 1 else: judge = 1 print(res)
s616091373
p03780
u519923151
1589478619
Python
Python (3.4.3)
py
Runtime Error
2130
414196
890
n,k = map(int, input().split()) al = list(map(int, input().split())) if sum(al) < k: print(n) exit() newal = sorted(al) for m in range(n): if newal[m] >k: cut = m break al = newal[:m] n = len(al) dp=[[0 for i in range(k*2)] for j in range(n)] dp[0][0]=1 res = 0 for h in range(n): judge =0 newal = sorted(al) xk = k-newal[h] newal.pop(h) for i in range(n-1): for j in range(k*2): if newal[i]<=j: #i+1番目の数字a[i]を足せるかも dp[i+1][j]=dp[i][j-newal[i]] or dp[i][j] else: #入る可能性はない dp[i+1][j]=dp[i][j] for l in range(xk,k*2): if judge ==1: break if dp[n-1][l] ==1: mins = l if l >=k: res += 1 judge = 1 else: judge = 1 print(res)
s493960813
p03780
u519923151
1589477712
Python
Python (3.4.3)
py
Runtime Error
2129
414712
897
n,k = map(int, input().split()) al = list(map(int, input().split())) if sum(al) < k: print(n) exit() dp=[[0 for i in range(k*2)] for j in range(n)] dp[0][0]=1 res = 0 for h in range(n): if newal[h] > k: pass else: judge =0 newal = sorted(al) xk = k-newal[h] newal.pop(h) for i in range(n-1): for j in range(k*2): if newal[i]<=j: #i+1番目の数字a[i]を足せるかも dp[i+1][j]=dp[i][j-newal[i]] or dp[i][j] else: #入る可能性はない dp[i+1][j]=dp[i][j] for l in range(xk,k*2): if judge ==1: break if dp[n-1][l] ==1: mins = l if l >=k: res += 1 judge = 1 else: judge = 1 print(res)
s715691118
p03780
u724687935
1587025921
Python
PyPy3 (2.4.0)
py
Runtime Error
2106
49628
719
N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() # [ok, ng) - Maximum # (ng, ok] - Minimum # ok が 最終的な答え ok = N ng = -1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 n = mid dp = set() dp.add(0) ans = set(x for x in range(max(0, K - A[n] + 1), K)) for i in range(N): a = A[i] if i == n or a >= K: continue for j in range(K - a - 1, -1, -1): if j in dp: if j + a in ans: rst = True break else: dp.add(j + a) else: rst = False if rst: ok = mid else: ng = mid print(ok)
s739324970
p03780
u724687935
1587023835
Python
PyPy3 (2.4.0)
py
Runtime Error
2133
465800
624
def solve(n): global N, K dp = [[0] * (K + 1) for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): a = 0 if i == n else A[i] for j in range(K + 1): dp[i + 1][min(K, j + a)] |= dp[i][j] dp[i + 1][j] |= dp[i][j] rst = any(dp[N][k] for k in range(K - A[n], K)) return rst N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() # [ok, ng) - Maximum # (ng, ok] - Minimum # ok が 最終的な答え ok = N ng = -1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid print(ok)
s461493376
p03780
u498487134
1584205983
Python
PyPy3 (2.4.0)
py
Runtime Error
2106
41916
1342
def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): N,K=MI() a=LI()#下位の連続するn枚が不要なはず a.sort() for i in range(N):#K以上ならば必要 if a[i]>=K: a=a[:i] N=len(a) #x番目の数が必要かどうかの判定 #必要なものだけで構成された集合をもとに考えれば良いわけではない,不必要な分も考えなければならない def ch(x): #使い回す,i番目まででjが作れるか dp=[False]*K dp[0]=True for i in range(N): if i==x: continue else: for j in range(K-1,a[i]-1,-1): dp[j]|=dp[j-a[i]] #K未満K-a[x]以上が作れれば良い for j in range(K-a[x],K): if dp[j]: return True return False ng=-1 ok=N while abs(ok-ng)>1: med=(ok+ng)//2 if ch(med): ok=med else: ng=med print(ng+1) main()
s892766207
p03780
u141610915
1583806086
Python
PyPy3 (2.4.0)
py
Runtime Error
2106
44764
555
import sys input = sys.stdin.readline N, K = map(int, input().split()) a = list(map(int, input().split())) a.sort() def check(x): dp = [0] * (K + 1) dp[0] = 1 for i in range(N): for j in range(K - 1, -1, -1): if i == x: continue if dp[j]: dp[min(K, j + a[i])] = dp[j] for j in range(max(0, K - a[x]), K): if dp[j]: return True return False #for i in range(N): print(check(i)) if check(0): print(0) exit(0) ok = N + 1 ng = 0 while ok - ng > 1: m = (ok + ng) // 2 if check(m): ok = m else: ng = m print(ok)
s542723987
p03780
u863442865
1583789405
Python
Python (3.4.3)
py
Runtime Error
543
12620
863
import numpy as np import itertools N, K = map(int, input().split()) a = list(map(int, input().split())) a.sort() def check(i): #i番目のカードを使わなかった時 dp = np.zeros(K, dtype = np.bool) #dp[k]はkが作れる時True #保持する情報はTrue/Falseのみで良いので1次元DPを上書きしていく(1回でまとめて) dp[0] = True for j in itertools.chain(a[:i], a[i+1:]): #i番目の無いカードセット dp[j:] = np.logical_or(dp[j:], dp[:-j]) #ある数jを使うと、j以降のもの(N-j)個と前から(N-j)個のどちらかがTrueのものは作れる return any(dp[K-a[i]:]) #K-a[i]~K-1のうちどれか作れるならa[i]は必要=True left = -1 right = N while right - left > 1: mid = (right + left)//2 if check(mid): right = mid else: left = mid print (ua)
s936795142
p03780
u863442865
1583711547
Python
PyPy3 (2.4.0)
py
Runtime Error
2129
427536
1391
''' 1枚抜いてDPをN枚についてやれば良い, がこれでは間に合わない そこで必要不要の境界を二分探索で探す するとO(N^2K)→O(NKlogN)となって間に合う もう1つの方法は分からない ''' def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations #from itertools import accumulate, product from bisect import bisect_left,bisect_right from math import floor, ceil #from operator import itemgetter #mod = 1000000007 N,K = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) a = a[:bisect_left(a, K)] n = len(a) def dp(num): dp = [[0]*(K) for _ in range(n)] dp[0][0] = 1 b = a[:num]+a[num+1:] #N-1個 for i in range(n-1): for j in range(K): if b[i]<=j: dp[i+1][j] = dp[i][j-b[i]] or dp[i][j] else: dp[i+1][j]=dp[i][j] return any(dp[n-1][K-a[num]:]) left = 0 right = N-1 while left<=right: mid = (left+right)//2 if dp(mid): right = mid-1 else: left = mid+1 print(right+1) if __name__ == '__main__': main()
s112313096
p03780
u905582793
1583137950
Python
PyPy3 (2.4.0)
py
Runtime Error
195
40560
852
from itertools import accumulate n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() acc = list(accumulate(a)) def maxsum(ls,k): l = len(ls) if l==0: return 0 dp = [0 for i in range(l+1)] dp[0] = 1 for i in range(1,l+1): dp[i] = (dp[i-1]|(dp[i-1]<<ls[i-1]))&(1<<k) for b in range(k-1,-1,-1): if dp[l] & 1<<b: return b for i in range(n): if a[i]>=k: a = a[:i] break n = len(a) if acc[n-1] < k: print(n) exit() sepa=[] for i in range(n-1): if acc[i]<a[i+1]: sepa.append(i) m=len(sepa) if m==0: print(0) exit() lf = 0 r = m-1 while lf<r: mid = (lf+r)//2 x=sepa[mid] sumx = acc[x] if maxsum(a[x+1:],k)+sumx >= k: r = mid else: lf = mid+1 if r==0: t=sepa[0] if maxsum(a[t+1:],k)+acc[t]>=k: print(0) else: print(sepa[r]+1) else: print(sepa[r]+1)
s512308653
p03780
u905582793
1583137911
Python
PyPy3 (2.4.0)
py
Runtime Error
203
40560
850
from itertools import accumulate n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() acc = list(accumulate(a)) def maxsum(ls,k): l = len(ls) if l==0: return 0 dp = [0 for i in range(l+1)] dp[0] = 1 for i in range(1,l+1): dp[i] = (dp[i-1]|(dp[i-1]<<ls[i-1]))&1<<k for b in range(k-1,-1,-1): if dp[l] & 1<<b: return b for i in range(n): if a[i]>=k: a = a[:i] break n = len(a) if acc[n-1] < k: print(n) exit() sepa=[] for i in range(n-1): if acc[i]<a[i+1]: sepa.append(i) m=len(sepa) if m==0: print(0) exit() lf = 0 r = m-1 while lf<r: mid = (lf+r)//2 x=sepa[mid] sumx = acc[x] if maxsum(a[x+1:],k)+sumx >= k: r = mid else: lf = mid+1 if r==0: t=sepa[0] if maxsum(a[t+1:],k)+acc[t]>=k: print(0) else: print(sepa[r]+1) else: print(sepa[r]+1)
s613488585
p03780
u905582793
1583137686
Python
PyPy3 (2.4.0)
py
Runtime Error
169
39408
842
from itertools import accumulate n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() acc = list(accumulate(a)) def maxsum(ls,k): l = len(ls) if l==0: return 0 dp = [0 for i in range(l+1)] dp[0] = 1 for i in range(1,l+1): dp[i] = dp[i-1]|(dp[i-1]<<ls[i-1]) for b in range(k-1,-1,-1): if dp[l] & 1<<b: return b for i in range(n): if a[i]>=k: a = a[:i] break n = len(a) if acc[n-1] < k: print(n) exit() sepa=[] for i in range(n-1): if acc[i]<a[i+1]: sepa.append(i) m=len(sepa) if m==0: print(0) exit() lf = 0 r = m-1 while lf<r: mid = (lf+r)//2 x=sepa[mid] sumx = acc[x] if maxsum(a[x+1:],k)+sumx >= k: r = mid else: lf = mid+1 if r==0: t=sepa[0] if maxsum(a[t+1],k)+acc[t]>=k: print(0) else: print(sepa[r]+1) else: print(sepa[r]+1)
s029904744
p03780
u905582793
1583137174
Python
PyPy3 (2.4.0)
py
Runtime Error
185
39408
709
from itertools import accumulate n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() acc = list(accumulate(a)) def maxsum(ls,k): l = len(ls) if l==0: return 0 dp = [0 for i in range(l+1)] dp[0] = 1 for i in range(1,l+1): dp[i] = dp[i-1]|(dp[i-1]<<ls[i-1]) for b in range(k-1,-1,-1): if dp[l] & 1<<b: return b for i in range(n): if a[i]>=k: a = a[:i] break n = len(a) if acc[n-1] < k: print(n) exit() sepa=[] for i in range(n-1): if acc[i]<a[i+1]: sepa.append(i) m=len(sepa) lf = 0 r = m-1 while lf<r: mid = (lf+r)//2 x=sepa[mid] sumx = acc[x] if maxsum(a[x+1:],k)+sumx >= k: r = mid else: lf = mid+1 print(sepa[r]+1)
s841112728
p03780
u905582793
1583136929
Python
PyPy3 (2.4.0)
py
Runtime Error
175
39408
706
from itertools import accumulate n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() acc = list(accumulate(a)) def maxsum(ls,k): l = len(ls) if l==0: return 0 dp = [0 for i in range(l+1)] dp[0] = 1 for i in range(1,l+1): dp[i] = dp[i-1]|(dp[i-1]<<ls[i-1]) for b in range(k-1,-1,-1): if dp[-1] & 1<<b: return b for i in range(n): if a[i]>=k: a = a[:i] break n = len(a) if acc[n-1] < k: print(n) exit() sepa=[] for i in range(n-1): if acc[i]<a[i+1]: sepa.append(i) m=len(sepa) l = 0 r = m-1 while l<r: mid = (l+r)//2 x=sepa[mid] sumx = acc[x] if maxsum(a[x+1:],k)+sumx >= k: r = mid else: l = mid+1 print(sepa[r]+1)
s862281627
p03780
u905582793
1583136383
Python
PyPy3 (2.4.0)
py
Runtime Error
171
39408
682
from itertools import accumulate n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() acc = list(accumulate(a)) def maxsum(ls,k): l = len(ls) dp = [0 for i in range(l+1)] dp[0] = 1 for i in range(1,l+1): dp[i] = dp[i-1]|(dp[i-1]<<ls[i-1]) for b in range(k-1,-1,-1): if dp[-1] & 1<<b: return b for i in range(n): if a[i]>=k: a = a[:i] break n = len(a) if acc[n-1] < k: print(n) exit() sepa=[] for i in range(n-1): if acc[i]<a[i+1]: sepa.append(i) m=len(sepa) l = 0 r = m-1 while l<r: mid = (l+r)//2 x=sepa[mid] sumx = acc[x] if maxsum(a[x+1:],k)+sumx >= k: r = mid else: l = mid+1 print(sepa[r]+1)
s826285184
p03780
u905582793
1583136229
Python
PyPy3 (2.4.0)
py
Runtime Error
173
39536
723
from itertools import accumulate n,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() acc = list(accumulate(a)) def maxsum(ls,k): l = len(ls) dp = [0 for i in range(l+1)] dp[0] = 1 for i in range(1,l+1): dp[i] = dp[i-1]|(dp[i-1]<<ls[i-1]) for b in range(k-1,-1,-1): if dp[-1] & 1<<b: return b for i in range(n): if a[i]>=k: a = a[:i] break n = len(a) if acc[n-1] < k: print(n) exit() sepa=[] for i in range(n-1): if acc[i]<a[i+1]: sepa.append(i) m=len(sepa) l = 0 r = m-1 while l<r: mid = (l+r)//2 x=sepa[mid] sumx = acc[x] if x < n-1: if maxsum(a[x+1:],k)+sumx >= k: r = mid else: l = mid+1 else: r -= 1 print(sepa[r]+1)
s824646830
p03780
u190086340
1581883791
Python
PyPy3 (2.4.0)
py
Runtime Error
2111
249608
1096
def args(): N, K = tuple(map(int, input().split())) Ai = tuple(map(int, input().split())) return N, K, Ai def solve(N, K, Ai): sum_a = sum(Ai) if sum_a < K: return N Ai = sorted(Ai) x, y = N, K + 10 MEMO = [[None for _ in range(y)] for _ in range(x)] def recur(ei, i, total): if not MEMO[ei][total] is None: return MEMO[ei][total] if not i < N: MEMO[ei][total] = True return if i == ei: # 選ばない recur(ei, i + 1, total) else: # 選ぶ if total + Ai[i] < K: recur(ei, i + 1, total + Ai[i]) # 選ばない recur(ei, i + 1, total) for i in range(N): recur(i, 0, 0) c = 0 for i in range(N): is_useless = True for j in range(K - Ai[i], K): if MEMO[i][j]: is_useless = False break if is_useless: c += 1 return c if __name__ == '__main__': res = solve(*args()) print(res)
s865376390
p03780
u190086340
1581545551
Python
PyPy3 (2.4.0)
py
Runtime Error
2140
589192
1565
def args(): N, K = tuple(map(int, input().split())) Ai = tuple(map(int, input().split())) return N, K, Ai def solve(N, K, Ai): sum_a = sum(Ai) if sum_a < K: return N Ai = sorted(Ai) def search(): def recur(i, total, target_card, range_head): if range_head <= total < K: if not MEMO[i][total] is None: return if range_head <= total < K: MEMO[i][total] = True return if not i < N or total > K: return if i == target_card: recur(i + 1, total, target_card, range_head) else: if not total > K: # 選ぶ recur(i + 1, total + Ai[i], target_card, range_head) # 選ばない recur(i + 1, total, target_card, range_head) count = 0 for target_card in range(N): # 2次元配列の生成: table[x][y] x, y = N + 1, K + 1 MEMO = [[None for _ in range(y)] for _ in range(x)] range_head = K - Ai[target_card] if range_head <= 0: MEMO[0][0] = True else: recur(0, 0, target_card, range_head) for i in range(N): if 0 < MEMO[i].count(True): count += 1 break return count res = search() return res if __name__ == '__main__': res = solve(*args()) print(res)
s197993258
p03780
u190086340
1581544864
Python
PyPy3 (2.4.0)
py
Runtime Error
2140
588936
1570
def args(): N, K = tuple(map(int, input().split())) Ai = tuple(map(int, input().split())) return N, K, Ai def solve(N, K, Ai): sum_a = sum(Ai) if sum_a < K: return N Ai = sorted(Ai) def search(): def recur(i, total, target_card, range_head): if range_head <= total < K: if not MEMO[i][total] is None: return if range_head <= total < K: MEMO[i][total] = True return if not i < N or total > K: return if i == target_card: recur(i + 1, total, target_card, range_head) else: if total < range_head: # 選ぶ recur(i + 1, total + Ai[i], target_card, range_head) # 選ばない recur(i + 1, total, target_card, range_head) count = 0 for target_card in range(N): # 2次元配列の生成: table[x][y] x, y = N + 1, K + 1 MEMO = [[None for _ in range(y)] for _ in range(x)] range_head = K - Ai[target_card] if range_head <= 0: MEMO[0][0] = True else: recur(0, 0, target_card, range_head) for i in range(N): if 0 < MEMO[i].count(True): count += 1 break return count res = search() return res if __name__ == '__main__': res = solve(*args()) print(res)
s915370680
p03780
u190086340
1581541142
Python
PyPy3 (2.4.0)
py
Runtime Error
2140
587656
1429
def args(): N, K = tuple(map(int, input().split())) Ai = tuple(map(int, input().split())) return N, K, Ai def solve(N, K, Ai): sum_a = sum(Ai) if sum_a < K: return N Ai = sorted(Ai) def search(): def recur(i, total, target_card, range_head): if range_head <= total < K: if not MEMO[i][total] is None: return if range_head <= total < K: MEMO[i][total] = True return if not i < N: return if i == target_card: recur(i + 1, total, target_card, range_head) else: if total < range_head: # 選ぶ recur(i + 1, total + Ai[i], target_card, range_head) # 選ばない recur(i + 1, total, target_card, range_head) count = 0 for target_card in range(N): x, y = N + 1, K + 100 MEMO = [[None for _ in range(y)] for _ in range(x)] range_head = K - Ai[target_card] recur(0, 0, target_card, range_head) for i in range(N): if 0 < MEMO[i].count(True): count += 1 break return count res = search() return res if __name__ == '__main__': res = solve(*args()) print(res)
s056439559
p03780
u190086340
1581540897
Python
PyPy3 (2.4.0)
py
Runtime Error
2140
586248
1515
def args(): N, K = tuple(map(int, input().split())) Ai = tuple(map(int, input().split())) return N, K, Ai def solve(N, K, Ai): sum_a = sum(Ai) if sum_a < K: return N Ai = sorted(Ai) def search(): def recur(i, total, target_card, range_head): if range_head <= total < K: if not MEMO[i][total] is None: return if range_head <= total < K: MEMO[i][total] = True return if not i < N: return if i == target_card: recur(i + 1, total, target_card, range_head) else: if total < range_head: # 選ぶ recur(i + 1, total + Ai[i], target_card, range_head) # 選ばない recur(i + 1, total, target_card, range_head) count = 0 for target_card in range(N): x, y = N + 1, K + 1 MEMO = [[None for _ in range(y)] for _ in range(x)] range_head = K - Ai[target_card] if range_head <= 0: MEMO[0][0] = True else: recur(0, 0, target_card, range_head) for i in range(N): if 0 < MEMO[i].count(True): count += 1 break return count res = search() return res if __name__ == '__main__': res = solve(*args()) print(res)
s257956910
p03780
u190086340
1581540197
Python
PyPy3 (2.4.0)
py
Runtime Error
2111
248712
1594
def args(): N, K = tuple(map(int, input().split())) Ai = tuple(map(int, input().split())) # print("N", N, "K", K) # print(Ai) # N, K = 5, 7 # Ai = [5, 2, 8, 11, 15] return N, K, Ai def solve(N, K, Ai): sum_a = sum(Ai) if sum_a < K: return N Ai = sorted(Ai) def search(): x, y = N + 1, K + 1 MEMO = [[None for _ in range(y)] for _ in range(x)] def recur(i, total, target_card, range_head): if range_head <= total < K: if not MEMO[i][total] is None: return if range_head <= total < K: MEMO[i][total] = True return if not i < N: return if i == target_card: recur(i + 1, total, target_card, range_head) else: if total < range_head: # 選ぶ recur(i + 1, total + Ai[i], target_card, range_head) # 選ばない recur(i + 1, total, target_card, range_head) count = 0 for target_card in range(N): range_head = K - Ai[target_card] if range_head <= 0: MEMO[i][0] = True else: recur(0, 0, target_card, range_head) for i in range(N): if 0 < MEMO[i].count(True): count += 1 break return count res = search() return res if __name__ == '__main__': res = solve(*args()) print(res)
s012232436
p03780
u353797797
1581108308
Python
Python (3.4.3)
py
Runtime Error
2104
3572
961
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): def need(m): s=1 for i in range(m+1,n): s|=s<<aa[i] s&=mask #print(m,bin(s),bin(s>>k-aa[m])) if s>>k-aa[m]:return True return False n,k=MI() mask=(1<<k)-1 #print(bin(mask)) aa=LI() aa.sort() for i in range(n): if aa[i]>k: aa=aa[:i] break n=len(aa) #print(aa) l=-1 r=n while l+1<r: m=(l+r)//2 while aa[m-1]==aa[m]:m-=1 #print(m,aa[m],need(m)) if need(m):r=m else:l=m print(l+1) main()
s157684673
p03780
u353797797
1581106977
Python
Python (3.4.3)
py
Runtime Error
2104
260516
908
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): def need(m): s=1 for i in range(m+1,n): a=aa[i] s|=s<<a s&=mask #print(m,bin(s)) for i in range(max(0,k-aa[m]),k): if s>>i&1:return True return False n,k=MI() mask=(1<<k+1)-1 #print(bin(mask)) aa=LI() aa.sort() #print(aa) l=-1 r=n while l+1<r: m=(l+r)//2 while aa[m-1]==aa[m]:m-=1 #print(m,aa[m],need(m)) if need(m):r=m else:l=m print(l+1) main()
s029041029
p03780
u672220554
1579279916
Python
PyPy3 (2.4.0)
py
Runtime Error
2072
41584
985
import bisect def main(): n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() l=0 r=n d = {} if sum(a)<k: print(n) else: while l!=r: i=(l+r)//2 ta = a[i] if ta in d.values(): flag = d[ta] elif ta>=k:flag=True else: flag = False na = a[:i]+a[i+1:] dp = [False for _ in range(k+1)] dp[0]=True for j in range(n-1): for m in range(k,0,-1): if m-na[j]>=0: dp[m]=dp[m] or dp[m-na[j]] if m != k and m>=k-ta and dp[m]: flag = True break if flag:break d[ta] = flag if flag: r=i else: l=i+1 print(l) main()
s778206151
p03780
u672220554
1579198284
Python
PyPy3 (2.4.0)
py
Runtime Error
174
39664
839
import bisect def main(): n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() l=0 r=n if sum(a)<k: print(n) else: while l!=r: i=(l+r)//2 ta = a[i] if ta>=k:flag=True else: na = a[:i]+a[i+1:] dp = [False for _ in range(k+1)] dp[0]=True for j in range(n-1): for m in range(k,0,-1): if m-na[j]>=0: dp[m]=dp[m] or dp[m-na[j]] if m != k and m>=k-ta and dp[m]: flag = True break if flag:break if flag: r=i else: l=i+1 print(l) main()
s003851154
p03780
u672220554
1579196648
Python
PyPy3 (2.4.0)
py
Runtime Error
2107
45276
500
import bisect n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() l=0 r=n while l!=r: i=(l+r)//2 ta = a[i] na = a[:i]+a[i+1:] dp = [False for _ in range(k+1)] dp[0]=True for j in range(n-1): for m in range(k,0,-1): if m-na[j]>=0: dp[m]=dp[m] or dp[m-na[j]] flag = False for j in range(k-ta,k): if dp[j]: flag = True break if flag: r=i else: l=i+1 print(l)
s388616400
p03780
u672220554
1579191979
Python
PyPy3 (2.4.0)
py
Runtime Error
2106
46360
543
import bisect n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() fa = a[:bisect.bisect_left(a,k)] fa.reverse() nn = len(fa) for i in range(nn): flag = 0 ta = fa[i] na = fa[:i]+fa[i+1:] dp = [False for _ in range(k+1)] dp[0]=True for j in range(nn-1): for l in range(k,0,-1): if l-na[j]>=0: dp[l]=dp[l] or dp[l-na[j]] for j in range(k-ta,k): if dp[j]: flag = 1 break if flag == 0: res = i break print(nn-i)