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
s213594269
p02270
u003309334
1465636209
Python
Python
py
Runtime Error
10
6316
1200
def moveRight(trug, start, stop): if trug[start][1]-trug[start][0] > 1: for i in xrange(stop-start): trug[start+i][1] -= 1 trug[start+i+1][0] -= 1 def moveLeft(trug, start, stop): if trug[start][1]-trug[start][0] > 1: for i in xrange(start-stop): trug[start-i][0] += 1 trug[start-i-1][1] += 1 def calcWeight(trug, w): temp = [ sum(w[trug[i][0]:trug[i][1]]) for i in xrange(len(trug)) ] return temp n, k = map(int, raw_input().split()) w = [] for i in xrange(n): w.append(input()) ta = n/k trug = [[i*ta, ta+i*ta] for i in xrange(k-1)] trug.append([(i+1)*ta, n]) trugw = calcWeight(trug, w) maxt = max(trugw) imaxt = trugw.index(maxt) mint = min(trugw) imint = trugw.index(mint) while True: if imaxt < imint: if mint+w[trug[imaxt][1]-1] < maxt: moveRight(trug, imaxt, imint) else: if mint+w[trug[imaxt][0]] < maxt: moveLeft(trug, imaxt, imint) trugw = calcWeight(trug, w) n = max(trugw) if n >= maxt: break else: maxt = n imaxt = trugw.index(maxt) mint = min(trugw) imint = trugw.index(mint) print maxt
s026182379
p02270
u003309334
1465636914
Python
Python
py
Runtime Error
10
6412
1253
def moveRight(trug, start, stop): if trug[start][1]-trug[start][0] > 1: for i in xrange(stop-start): trug[start+i][1] -= 1 trug[start+i+1][0] -= 1 def moveLeft(trug, start, stop): if trug[start][1]-trug[start][0] > 1: for i in xrange(start-stop): trug[start-i][0] += 1 trug[start-i-1][1] += 1 def calcWeight(trug, w): temp = [ sum(w[trug[i][0]:trug[i][1]]) for i in xrange(len(trug)) ] return temp n, k = map(int, raw_input().split()) w = [] for i in xrange(n): w.append(input()) if k == 1: trug = [[0, n]] else: ta = n/k trug = [[i*ta, ta+i*ta] for i in xrange(k-1)] trug.append([(i+1)*ta, n]) trugw = calcWeight(trug, w) maxt = max(trugw) imaxt = trugw.index(maxt) mint = min(trugw) imint = trugw.index(mint) while True: if imaxt < imint: if mint+w[trug[imint-1][1]-1] < maxt: moveRight(trug, imaxt, imint) else: if mint+w[trug[imint+1][0]] < maxt: moveLeft(trug, imaxt, imint) trugw = calcWeight(trug, w) n = max(trugw) if n >= maxt: break else: maxt = n imaxt = trugw.index(maxt) mint = min(trugw) imint = trugw.index(mint) print maxt
s572610520
p02270
u742013327
1477383138
Python
Python3
py
Runtime Error
0
0
500
def cal(truck_num, cargos): p = [] for i in range(len(cargos) - truck_num + 1): if truck_num > 1: p.append(max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))) else: return sum(cargos) return min(p) if __name__ == "__main__": line = input() truck_num = line.split(" ")[1] line_num = line.split(" ")[0] cargos = [] for cargos in range(line_num): cargos.append(int(input())) print(cal(truck_num,cargos))
s076856852
p02270
u742013327
1477383165
Python
Python3
py
Runtime Error
0
0
500
def cal(truck_num, cargos): p = [] for i in range(len(cargos) - truck_num + 1): if truck_num > 1: p.append(max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))) else: return sum(cargos) return min(p) if __name__ == "__main__": line = input() truck_num = line.split(" ")[1] line_num = line.split(" ")[0] cargos = [] for cargos in range(line_num): cargos.append(int(input())) print(cal(truck_num,cargos))
s210396853
p02270
u659302741
1478163733
Python
Python3
py
Runtime Error
60
7796
1578
def calc_k(p, ws): k = 1 s = 0 for w in ws: if w > p: return None elif s + w <= p: s += w else: k += 1 s = w return k def search_minimum_p_internal(lp, rp, k, ws): "?????????P????????????????????¢?´¢??????" cp = (lp + rp) // 2 k1 = calc_k(cp, ws) if k1 == k: # ???????????¨????????????????°?????????¨???k??°???????????????????????? k2 = calc_k(cp - 1, ws) if k2 == None or k2 > k: # cp???k??°???????????????????????????p???????°??????§?????? return cp else: # ???????°???????p????????¨?????? return search_minimum_p_internal(lp, cp - 1, k, ws) elif k1 < k: # ???????????¨???????????????k??°???????°?????????????????????§???????????????????????????????????? return search_minimum_p_internal(lp, cp - 1, k, ws) else: # ???????????¨???????????????k??°????????????????????????????????????????????????????¶????????????? return search_minimum_p_internal(cp + 1, rp, k, ws) def search_minimum_p(k, ws): """ max(P) = max(wi) * max(n) ????????¨???????????????1??°?????¨???????????????????????? min(P) = max(wi) ?°?????????¨??????????????????????????§???????????????????????????????????? """ maxp = 10000 * 100000 minp = max(ws) return search_minimum_p_internal(minp, maxp, k, ws) n, k = map(int, input().split()) ws = [] for i in range(n): ws.append(int(input())) print(search_minimum_p(k, ws))
s237093572
p02270
u358919705
1478515750
Python
Python3
py
Runtime Error
50
7732
516
n, k = map(int, input().split()) ww = [int(input()) for _ in range(n)] def chk(p): c = 1 s = 0 for w in ww: if w > p: return False if s + w <= p: s += w else: c += 1 s = w return c <= k def search(l, r): if r - l < 10: for i in range(l, r): if chk(i): return i m = (l + r) // 2 if chk(m): return search(l, m) else: return search(m, r) print(search(0, 2 ** 30))
s484015856
p02270
u358919705
1478516054
Python
Python3
py
Runtime Error
20
7756
557
n, k = map(int, input().split()) ww = [int(input()) for _ in range(n)] def chk(p): c = 1 s = 0 for w in ww: if w > p: return False if s + w <= p: s += w else: c += 1 s = w if c > k: return False return True def search(l, r): if r - l < 10: for i in range(l, r): if chk(i): return i m = (l + r) // 2 if chk(m): return search(l, m) else: return search(m, r) print(search(0, 2 ** 30))
s769757037
p02270
u742013327
1481621719
Python
Python3
py
Runtime Error
0
0
863
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_B #???????????? 17:55~ def maxHeapify(heap, index): left_index = 2 * index right_index = 2 * index + 1 if left_index < len(heap) and heap[left_index] > heap[index]: largest_index = left_index else: largest_index = index if right_index < len(heap) and heap[right_index] > heap[largest_index]: largest_index = right_index if not largest_index == index: heap[index], heap[largest_index] = heap[largest_index], heap[index] maxHeapify(heap, largest_index) def main(): n_node = int(input()) target_list = [""] + [int(n) for n in input().split()] for i in range(int(len(target_list) / 2), 0, -1): print(i) maxHeapify(target_list, i) print(*target_list) if __name__ == "__main__": main()
s042335981
p02270
u923668099
1484475997
Python
Python3
py
Runtime Error
20
7920
1557
import sys import math def is_capable(n, k, w, P): track = 0 cnt = 0 i = 0 while cnt < k: if i == n: return True if track + w[i] > P: track = 0 cnt += 1 else: track += w[i] i += 1 return False pass # ??\?????¨ n, k = map(int, sys.stdin.readline().split()) w = [] for i in range(n): w.append(int(sys.stdin.readline().strip())) ''' print(n,k) print(w) ''' # ????????¨ if k == 1: ans = sum(w) print(ans) elif n == 1: ans = w[0] print(ans) else: max_p = sum(w) min_p = math.ceil(max_p / k) - 1 capable = [None] * (max_p - min_p + 1) capable[0] = False capable[-1] = True bottom = 0 top = len(capable) while bottom < top: mid = (bottom + top) // 2 if capable[mid] is None: capable[mid] = is_capable(n, k, w, min_p + mid) if capable[mid] == True: if capable[mid - 1] is None: capable[mid - 1] = is_capable(n, k, w, min_p + mid - 1) if capable[mid - 1] == False: bnd = mid break else: top = mid - 1 elif capable[mid] == False: if capable[mid + 1] is None: capable[mid + 1] = is_capable(n, k, w, min_p + mid + 1) if capable[mid + 1] == True: bnd = mid + 1 break else: bottom = mid + 2 ans = min_p + bnd print(ans) # print(capable)
s118948428
p02270
u089830331
1484672034
Python
Python3
py
Runtime Error
40
7776
719
def get_min_p(offset, length, k, arr): if k == 2: min_diff = 100 p = 0 for i in range(1, length): a = sum(arr[offset:offset + i]) b = sum(arr[offset + i:]) if abs(a - b) < min_diff: min_diff = abs(a - b) p = max(a, b) #print("arr:{}, i:{}, p:{}".format( # arr[offset:offset + length], i, p)) return p else: p = [100] * (len(arr) - k + 2) for i in range(1, len(arr) - k + 2): #print("p:{}, i:{}".format(p, i)) a = get_min_p(offset + i, length - i, k - 1, arr) b = sum(arr[:offset + i]) p[i] = max(a, b) return min(p) n, k = map(int, input().split()) a = [int(input()) for i in range(n)] print(get_min_p(0, n, k, a))
s730459727
p02270
u918276501
1485111812
Python
Python3
py
Runtime Error
0
0
515
import sys n, k = map(int, input().split()) w = tuple(map(int, sys.stdin.readlines())) w = tuple(map(int, input().split())) p = max(w) s = sum(w) if n <= k: print(p) elif k == 1: print(s) else: a = max(p, s//k) while True: l = [a] for i in range(n): d = l[-1] - w[i] if d < 0: l.append(a-w[i]) else: l[-1] = d i += 1 if len(l) > k: a += 1 else: break print(a)
s318443766
p02270
u148628801
1487138414
Python
Python3
py
Runtime Error
0
0
797
import sys import math def be_able_to_convey(w, k, p): counter = 0 cur_weight = 0 for wi in w: if wi > p: return False cur_weight += wi if(cur_weight > p): cur_weight = wi counter += 1 if(counter >= k): return False return True fin = open("test.txt", "r") #fin = sys.stdin n, k = map(int, fin.readline().split()) w = [0 for i in range(n)] w_max = 0 for i in range(n): w[i] = int(fin.readline()) w_max = max(w[i], w_max) pmin = 1 pmax = math.ceil(w_max * w_max // k) while pmin < pmax: p = math.ceil((pmin + pmax) / 2) if p == pmin or p == pmax: if be_able_to_convey(w, k, pmax): if be_able_to_convey(w, k, pmin): p = pmin else: p = pmax else: p = pmin break if not be_able_to_convey(w, k, p): pmin = p else: pmax = p print(p)
s094479657
p02270
u831244171
1487341046
Python
Python3
py
Runtime Error
20
7684
770
import sys def binarySearch(t,w,p): left = 0 right = p while left < right: middle = (left + right) // 2 if hantei(t,w,middle): left = middle + 1 else: right = middle return left def hantei(t,w,p): track_on = [0]*t j = 0 for i in range(t): temp = track_on[i] while True: temp += w[j] if temp > p: break else: if j == len(w): return False track_on[i] = temp j += 1 return True nimotsu, track = map(int,input().split()) weight = list(map(int,sys.stdin.readlines())) max_p = sum(weight) // track + 1 print(binarySearch(track,weight,max_p))
s077455999
p02270
u086566114
1488466327
Python
Python
py
Runtime Error
0
0
2267
# -*- coding: utf-8 -*- def check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, maximum_weight): """check the numbers that are loadable in tracks Args: cargo_weight_list: cargo weight list number_of_tracks: the number of tracks Returns: the number of cargos that are loadable in tracks """ counter = 0 number_of_loaded_cargo = 0 weight_iter = iter(cargo_weight_list) while counter < number_of_tracks: current_track_weight = 0 next_weight = weight_iter.next() while current_track_weight + next_weight <= maximum_weight: current_track_weight += next_weight number_of_loaded_cargo += 1 if number_of_loaded_cargo == number_of_all_cargo: return number_of_all_cargo else: next_weight = weight_iter.next() counter += 1 return number_of_loaded_cargo def find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks): """find the minimum of maximum weight s.t all of the cargos can be loaded into tracks. (binary search is used. the number of loadable cargos monotonicaly increases as the maximum weight increases) Args: cargo_weight_list: cargo weight list numbef of all cargo: the number of all cargos number of tracks: the number of tracks Returns: minumim number of maximum track weight that are needed to load all of the cargos """ left = max(cargo_weight_list) right = sum(cargo_weight_list) while (right - left) > 0: middle = (right + left) / 2 the_number_of_loadable_cagos = check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, middle) if the_number_of_loadable_cagos >= number_of_all_cargo: right = middle else: left = middle + 1 return right def main(): number_of_all_cargo, number_of_tracks = [int(x) for x in raw_input().split(' ')] cargo_weight_list = [int(raw_input()) for _ in xrange(number_of_all_cargo)] print find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks) if __name__ == '__main__': main()
s473266969
p02270
u086566114
1488466881
Python
Python
py
Runtime Error
0
0
2267
# -*- coding: utf-8 -*- def check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, maximum_weight): """check the numbers that are loadable in tracks Args: cargo_weight_list: cargo weight list number_of_tracks: the number of tracks Returns: the number of cargos that are loadable in tracks """ counter = 0 number_of_loaded_cargo = 0 weight_iter = iter(cargo_weight_list) while counter < number_of_tracks: current_track_weight = 0 next_weight = weight_iter.next() while current_track_weight + next_weight <= maximum_weight: current_track_weight += next_weight number_of_loaded_cargo += 1 if number_of_loaded_cargo == number_of_all_cargo: return number_of_all_cargo else: next_weight = weight_iter.next() counter += 1 return number_of_loaded_cargo def find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks): """find the minimum of maximum weight s.t all of the cargos can be loaded into tracks. (binary search is used. the number of loadable cargos monotonicaly increases as the maximum weight increases) Args: cargo_weight_list: cargo weight list numbef of all cargo: the number of all cargos number of tracks: the number of tracks Returns: minumim number of maximum track weight that are needed to load all of the cargos """ left = max(cargo_weight_list) right = sum(cargo_weight_list) while (right - left) > 0: middle = (right + left) / 2 the_number_of_loadable_cagos = check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, middle) if the_number_of_loadable_cagos >= number_of_all_cargo: right = middle else: left = middle + 1 return right def main(): number_of_all_cargo, number_of_tracks = [int(x) for x in raw_input().split(' ')] cargo_weight_list = [int(raw_input()) for _ in xrange(number_of_all_cargo)] print find_the_minimum_of_maximum_weight(cargo_weight_list, number_of_all_cargo, number_of_tracks) if __name__ == '__main__': main()
s005436432
p02270
u130834228
1490521096
Python
Python3
py
Runtime Error
0
0
219
n, k = map(int, input().split()) w = [0 for i in range(n)] sumw = [0 for i in range(k)] for i in range(n): w[i] = input() w.sort() w.reverse() for i in range(w): sumw[min(sumw.index)] += w[i] print(min(sumw))
s573185945
p02270
u279605379
1499669598
Python
Python3
py
Runtime Error
0
0
512
#ALDS1_4-D Allocation from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = 0 c += 1 else: tr += tmp c+=1 if c>k:return False else:return True n,k = input().split() w = [] w = deque() for i in range(int(n)): w.append(int(input())) p = max(w) while(1): x=w.copy() if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1
s484588951
p02270
u279605379
1499669820
Python
Python3
py
Runtime Error
0
0
530
from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): print(c,tr) tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k:return False else:return True n,k = input().split() w = [] w = deque() for i in range(int(n)): w.append(int(input())) p = max(w) while(1): x=w.copy() print("p",p) if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1
s448922612
p02270
u279605379
1499669947
Python
Python3
py
Runtime Error
0
0
562
#ALDS1_4-D Allocation from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): print(c,tr) tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k:return False else:return True n,k = input().split() w = [] w = deque() for i in range(int(n)): t = input() w.append(int(t)) p = max(w) while(1): x=w.copy() print("p",p) if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1
s098973491
p02270
u279605379
1499670325
Python
Python3
py
Runtime Error
0
0
508
#ALDS1_4-D Allocation from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k:return False else:return True n,k = input().split() w = [] w = deque() for i in range(int(n)): t = input() w.append(int(t)) p = max(w) while(1): x=w.copy() if(pIsAccptbl(x,int(k),p)): break else: p+=1
s010555079
p02270
u279605379
1499670356
Python
Python3
py
Runtime Error
0
0
492
#ALDS1_4-D Allocation import collections def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k:return False else:return True n,k = input().split() w = collections.deque() for i in range(int(n)): w.append(int(input())) p = max(w) while(1): x=w.copy() if(pIsAccptbl(x,int(k),p)): break else: p+=1
s667300575
p02270
u279605379
1499670417
Python
Python3
py
Runtime Error
0
0
28
from collectins import deque
s026867857
p02270
u279605379
1499670446
Python
Python3
py
Runtime Error
0
0
37
from collectins import deque print(1)
s426923394
p02270
u279605379
1499670508
Python
Python3
py
Runtime Error
0
0
538
#ALDS1_4-D Allocation from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k: return False else: return True n,k = input().split() w = collections.deque() for i in range(int(n)): w.append(int(input())) p = max(w) while(1): x=w.copy() if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1
s858728779
p02270
u279605379
1499670685
Python
Python3
py
Runtime Error
0
0
523
from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k: return False else: return True n,k = input().split() w = collections.deque() for i in range(int(n)): w.append(int(input())) p = max(w) ''' while(1): x=w.copy() if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1 '''
s881376055
p02270
u279605379
1499670697
Python
Python3
py
Runtime Error
0
0
524
from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k: return False else: return True n,k = input().split() w = collections.deque() ''' for i in range(int(n)): w.append(int(input())) p = max(w) while(1): x=w.copy() if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1 '''
s732358109
p02270
u279605379
1499670727
Python
Python3
py
Runtime Error
0
0
54
from collections import deque w = collections.deque()
s546334886
p02270
u279605379
1499670768
Python
Python3
py
Runtime Error
0
0
526
#ALDS1_4-D Allocation from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k: return False else: return True n,k = input().split() w = deque() for i in range(int(n)): w.append(int(input())) p = max(w) while(1): x=w.copy() if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1
s973389304
p02270
u279605379
1499670841
Python
Python3
py
Runtime Error
0
0
553
#ALDS1_4-D Allocation from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k: return False else: return True n,k = input().split() w = deque() for i in range(int(n)): w.append(int(input())) p = max(w) while(1): x=w.copy() ''' if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1 ''' break
s868178610
p02270
u279605379
1499670877
Python
Python3
py
Runtime Error
0
0
546
#ALDS1_4-D Allocation from collections import deque def pIsAccptbl(w,k,p): tr = 0 c = 0 while(w): tmp = w.popleft() if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp c+=1 if c>k: return False else: return True n,k = input().split() w = deque() for i in range(int(n)): w.append(int(input())) p = max(w) while(1): x=deque() x=w.copy() if(pIsAccptbl(x,int(k),p)): print(p) break else: p+=1
s661294511
p02270
u279605379
1499740642
Python
Python3
py
Runtime Error
0
0
1112
from collections import deque def cndP(l,n,p1,p2): d = set() length = len(l) for i in range(length-n+1): s = sum(l[i:i+n]) #print("s:",s) if p2 == None: if p1 < s: d.add(s) else: if p1 < c < p2: d.add(s) return sorted(d) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = deque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = [] for i in range(n): e = int(input()) w.append(e) n=2 p = max(w) p1 = p p2 = None if(pIsAccptbl(w,k,p)): print(p) else: while(1): #print("p1,p2:",p1,p2) s = cndP(w,n,p1,p2) #print("s:",s) if s==[]: #print(p2) break; for i in s: if(pIsAccptbl(w,k,i)): p2 = i break p1 = i n+=1
s184687851
p02270
u279605379
1499740672
Python
Python3
py
Runtime Error
0
0
1012
from collections import deque def cndP(l,n,p1,p2): d = set() length = len(l) for i in range(length-n+1): s = sum(l[i:i+n]) if p2 == None: if p1 < s: d.add(s) else: if p1 < c < p2: d.add(s) return sorted(d) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = deque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = [] for i in range(n): e = int(input()) w.append(e) n=2 p = max(w) p1 = p p2 = None if(pIsAccptbl(w,k,p)): print(p) else: while(1): s = cndP(w,n,p1,p2) if s==[]: break; for i in s: if(pIsAccptbl(w,k,i)): p2 = i break p1 = i n+=1
s691240671
p02270
u279605379
1499825757
Python
Python3
py
Runtime Error
0
0
1100
from collections import deque def cndP(l,n,p1,p2): d = set() length = len(l) for i in range(length-n+1): s = sum(l[i:i+n]) if p2 == None: if p1 < s: d.add(s) else: if p1 < s < p2: d.add(s) return sorted(d) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = deque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] #w = [int(x) for x in input().split()] for i in range(n): e = int(input()) w.append(e) n=2 p = max(w) p1 = p p2 = None if(pIsAccptbl(w,k,p)): print(p) else: while(1): s = cndP(w,n,p1,p2) if s==[]: print(p2) break; for i in s: if(pIsAccptbl(w,k,i)): p2 = i break if(p2==None): p1 = i n+=1
s317196787
p02270
u279605379
1499825768
Python
Python3
py
Runtime Error
0
0
1061
from collections import deque def cndP(l,n,p1,p2): d = set() length = len(l) for i in range(length-n+1): s = sum(l[i:i+n]) if p2 == None: if p1 < s: d.add(s) else: if p1 < s < p2: d.add(s) return sorted(d) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = deque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] for i in range(n): e = int(input()) w.append(e) n=2 p = max(w) p1 = p p2 = None if(pIsAccptbl(w,k,p)): print(p) else: while(1): s = cndP(w,n,p1,p2) if s==[]: print(p2) break; for i in s: if(pIsAccptbl(w,k,i)): p2 = i break if(p2==None): p1 = i n+=1
s148720496
p02270
u279605379
1499827384
Python
Python3
py
Runtime Error
0
0
1061
from collections import deque def cndP(l,n,p1,p2): d = set() length = len(l) for i in range(length-n+1): s = sum(l[i:i+n]) if p2 == None: if p1 < s: d.add(s) else: if p1 < s < p2: d.add(s) return sorted(d) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = deque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] for i in range(n): e = int(input()) w.append(e) n=2 p = max(w) p1 = p p2 = None if(pIsAccptbl(w,k,p)): print(p) else: while(1): s = cndP(w,n,p1,p2) if s==[]: print(p2) break; for i in s: if(pIsAccptbl(w,k,i)): p2 = i break if(p2==None): p1 = i n+=1
s293570954
p02270
u279605379
1499910878
Python
Python3
py
Runtime Error
0
0
798
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy()) sorted_st = sorted(st) for i in sorted_st: if pIsAccptbl(w,k,i): print(i) break
s254153666
p02270
u279605379
1499910910
Python
Python3
py
Runtime Error
0
0
1254
from collections import deque def cndP(l,n,p1,p2): d = set() min = sum(l[:]) length = len(l) for i in range(length-n+1): s = sum(l[i:i+n]) if s < min: min = s if p2 == None: if p1 < s: d.add(s) else: if p1 < s < p2: d.add(s) d.add(min) return sorted(d) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = deque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) p = max(w) if(pIsAccptbl(w,k,p)): print(p) else: n=2 p1 = p p2 = None while(1): s = cndP(w,n,p1,p2) if not p2 == None: if s[0] > p2: print(p2) break for i in s: if(pIsAccptbl(w,k,i)): p2 = i break if(p2==None): p1 = i if (n == len(w)): print(p2) break n+=1
s338477852
p02270
u279605379
1499911043
Python
Python3
py
Runtime Error
0
0
721
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy()) sorted_st = sorted(st)
s689710759
p02270
u279605379
1499911057
Python
Python3
py
Runtime Error
0
0
698
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy())
s582556677
p02270
u279605379
1499911071
Python
Python3
py
Runtime Error
0
0
1382
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy())
s705607465
p02270
u279605379
1499911077
Python
Python3
py
Runtime Error
0
0
1375
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w)
s283773204
p02270
u279605379
1499911102
Python
Python3
py
Runtime Error
0
0
1309
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy)
s401842439
p02270
u279605379
1499911114
Python
Python3
py
Runtime Error
0
0
1275
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy)
s675816552
p02270
u279605379
1499911121
Python
Python3
py
Runtime Error
0
0
1358
from collections import deque def cndP(w): if len(w)>1: x = w.pop() w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy)
s085635459
p02270
u279605379
1499911150
Python
Python3
py
Runtime Error
0
0
1380
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy)
s077917976
p02270
u279605379
1499911279
Python
Python3
py
Runtime Error
0
0
1382
from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() from collections import deque def cndP(w): if len(w)>1: x = w.pop() cndP(w.copy()) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = w.copy() while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(w.copy())
s317761402
p02270
u279605379
1499912413
Python
Python3
py
Runtime Error
30
8144
895
from collections import deque def copyDeque(d): x = deque() for i in d: x.append(i) return x def cndP(w): if len(w)>1: x = w.pop() cndP(copyDeque(w)) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = copyDeque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(copyDeque(w)) sorted_st = sorted(st) for i in sorted_st: if pIsAccptbl(w,k,i): print(i) break
s941778932
p02270
u279605379
1499912426
Python
Python3
py
Runtime Error
30
8160
895
from collections import deque def copyDeque(d): x = deque() for i in d: x.append(i) return x def cndP(w): if len(w)>1: x = w.pop() cndP(copyDeque(w)) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = copyDeque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) st = set() cndP(copyDeque(w)) sorted_st = sorted(st) for i in sorted_st: if pIsAccptbl(w,k,i): print(i) break
s151897430
p02270
u279605379
1499914229
Python
Python3
py
Runtime Error
0
0
961
from collections import deque sys.setrecursionlimit(100000) def copyDeque(d): x = deque() for i in d: x.append(i) return x def cndP(w): if len(w)>1: x = w.pop() cndP(copyDeque(w)) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = copyDeque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] w = deque([int(x) for x in input().split()]) #for i in range(n): # w.append(int(input())) st = set() cndP(copyDeque(w)) sorted_st = sorted(st) for i in sorted_st: if pIsAccptbl(w,k,i): print(i) break
s386706413
p02270
u279605379
1499914258
Python
Python3
py
Runtime Error
0
0
924
from collections import deque import sys sys.setrecursionlimit(100000) def copyDeque(d): x = deque() for i in d: x.append(i) return x def cndP(w): if len(w)>1: x = w.pop() cndP(copyDeque(w)) w.append(x) s = 0 while(len(w)>0): s += w.pop() st.add(s) else: st.add(w[0]) def pIsAccptbl(w,k,p): tr = 0 c = 0 d = copyDeque(w) while(d): tmp = d.popleft() if(tmp > p): return False if( tr + tmp > p): tr = tmp c += 1 else: tr += tmp if c+1>k: return False return True n,k = [int(x) for x in input().split()] for i in range(n): w.append(int(input())) st = set() cndP(copyDeque(w)) sorted_st = sorted(st) for i in sorted_st: if pIsAccptbl(w,k,i): print(i) break
s520470033
p02270
u279605379
1500345279
Python
Python3
py
Runtime Error
0
0
1077
from collections import deque def isPa(w,k,p): counter = 0 s = 0 n = 1 wlen = len(w) while(True): if( sum([s:s+n]) >= p): s = s+n n = 1 counter += 1 else: n += 1 if( s+n == len(a)): counter += 1 break if(counter > k): return False else: return true def MaxInP(w,k,p): maxinp = 0 tmp = 0 d = deque(w) while(d): tmp += d.popleft(); if(tmp > p): if(tmp > maxinp): maxinp = tmp tmp = 0 return maxinp n,k = [int(x) for x in input().split()] w = deque() for i in range(n): w.append(int(input())) mean = int(sum(w)/k) maxinp = MaxInP(w,k,mean) l = range(mean,maxinp) if k == 1: print(mean) else: minP = mean maxP = maxinp while(True): m = int ((minP + maxP)/2) if ( isPa(w,k,m) ): maxP = m else: minP = m if (minP+1 == maxP): print(maxP) break
s516732926
p02270
u279605379
1500345428
Python
Python3
py
Runtime Error
0
0
1073
from collections import deque def isPa(w,k,p): counter = 0 s = 0 n = 1 wlen = len(w) while(True): if( sum(w[s:s+n]) >= p): s = s+n n = 1 counter += 1 else: n += 1 if( s+n == len(a)): counter += 1 break if(counter > k): return False else: return True def MaxInP(w,k,p): maxinp = 0 tmp = 0 d = deque(w) while(d): tmp += d.popleft(); if(tmp > p): if(tmp > maxinp): maxinp = tmp tmp = 0 return maxinp n,k = [int(x) for x in input().split()] w = [] for i in range(n): w.append(int(input())) mean = int(sum(w)/k) maxinp = MaxInP(w,k,mean) l = range(mean,maxinp) if k == 1: print(mean) else: minP = mean maxP = maxinp while(True): m = int ((minP + maxP)/2) if ( isPa(w,k,m) ): maxP = m else: minP = m if (minP+1 == maxP): print(maxP) break
s398252290
p02270
u519227872
1501760693
Python
Python3
py
Runtime Error
0
0
505
n = int(input()) S = list(map(int, input().split())) q = int(input()) T = map(int, input().split()) def binarySearch(array, target): l = len(array) first_half = array[:l//2] second_half = array[l//2:] if first_half == []: return False if first_half[-1] == target: return True elif first_half[-1] < target: return binarySearch(second_half, target) else: return binarySearch(first_half, target) a = 0 for t in T: a += binarySearch(S, t) print(a)
s357280531
p02270
u856963614
1509984967
Python
Python3
py
Runtime Error
30
7808
756
nk=input().split() n=int(nk[0]) k=int(nk[1]) weight=[int(input()) for i in range(n)] def ok(m): load=0 track=1 # sum all the weight and count the track number we need for i in range(n): load+=weight[i] if load==m: load=0 if i!=n-1: track+=1 elif load>m: if weight[i]>m: return False else: load=weight[i] track+=1 else: continue if track<=k: return True else: return False low=0 high=sum(weight)//(k//2) while low+1<high: # low<mid<high #not ok(l) and ok(h) mid=(low+high)//2 if ok(mid): high=mid else: low=mid print(high)
s667737564
p02270
u426534722
1516638923
Python
Python3
py
Runtime Error
0
0
465
import sys readline = sys.stdin.readline N, K = map(int, input().split()) W = tuple(int(readline()) for _ in range(n)) ma = max(W) def check(x): if x < ma: return False use = 1 rest = x for w in W: if rest >= w: rest -= w else: rest = x - w use += 1 return use <= K l = 0 r = sum(W) while r - l > 1: m = (r + l) // 2 if check(m): r = m else: l = m print(r)
s061977688
p02270
u426534722
1516639182
Python
Python3
py
Runtime Error
0
0
466
import sys readline = sys.stdin.readline N, K = map(int, input().split()) W = {map(int, sys.stdin.read().splitlines())} ma = max(W) def check(x): if x < ma: return False use = 1 rest = x for w in W: if rest >= w: rest -= w else: rest = x - w use += 1 return use <= K l = 0 r = sum(W) while r - l > 1: m = (r + l) // 2 if check(m): r = m else: l = m print(r)
s789863230
p02270
u426534722
1516639543
Python
Python3
py
Runtime Error
0
0
464
import sys readline = sys.stdin.readline N, K = map(int, input().split()) W = tuple(map(int, sys.stdin.splitlines())) ma = max(W) def check(x): if x < ma: return False use = 1 rest = x for w in W: if rest >= w: rest -= w else: rest = x - w use += 1 return use <= K l = 0 r = sum(W) while r - l > 1: m = (r + l) // 2 if check(m): r = m else: l = m print(r)
s062802487
p02270
u138546245
1523868937
Python
Python3
py
Runtime Error
0
0
734
def allocate(count, weights): def loadable_counts(maxweight): n = 0 l = 0 c = count for w in weights: l += w if l > maxweight: l = w c -= 1 if c <= 0: return n n += 1 return n i = 0 j = max(weights) * len(weights) // count while i < j: mid = (i + j) // 2 if loadable_counts(mid) < len(weights): i = mid + 1 else: j = mid return i def run(): k, n = [int(i) for i in input().split()] ws = [] for i in sys.stdin: ws.append(int(i)) print(allocate(n, ws)) if __name__ == '__main__': run()
s727338188
p02270
u605879293
1523947222
Python
Python3
py
Runtime Error
20
5656
594
from itertools import combinations def func(w, partition): sum_list = [sum(w[0:partition[0]])] for i in range(len(partition)): if i < len(partition) - 1: sum_list.append(sum(w[partition[i]:partition[i+1]])) else: sum_list.append(sum(w[partition[i]:])) return max(sum_list) n, k = [int(x) for x in input().split()] w = [int(input()) for _ in range(n)] w_indices = [i for i in range(1, n)] partition_list = combinations(w_indices, k-1) p_list = [] for partition in partition_list: p_list.append(func(w, partition)) print(min(p_list))
s755468601
p02270
u005964097
1525926023
Python
Python3
py
Runtime Error
0
0
542
def min_sufficient_load(w, k): return check(w, k, 0, sum(w)) def check(w, k, p1, p2): trunk_no = 1 temp = 0 m = 1+(p1 + p2)>>1 for i in w: if temp + i <= m: temp += i else: trunk_no += 1 temp = i if trunk_no > k: return check(w, k, m, p2) else: if m - p2 == 0: return m return check(w, k, p1, m) if __name__=="__main__": k,n = map(int,input()) w = [] for i in n: w.append(i) min_sufficient_load(w,k)
s431643629
p02270
u005964097
1525951873
Python
Python3
py
Runtime Error
0
0
673
def min_sufficient_load(w, k): return check(w, k, 0, sum(w)) def check(w, k, p1, p2): trunk_no = 1 temp = 0 m = 1+(p1 + p2)>>1 for i in w: if temp + i <= m: temp += i   if temp==m:   trunk_no+=1   temp = 0 else: trunk_no += 1 temp = i if trunk_no > k: return check(w, k, m, p2) else: if m - p2 == 0: return m return check(w, k, p1, m) if __name__=="__main__": n,k = map(int,input().split(" ")) w = [] for i in range(n): w.append(int(input())) print(min_sufficient_load(w,k))
s889666573
p02270
u005964097
1525951922
Python
Python3
py
Runtime Error
20
5600
655
def min_sufficient_load(w, k): return check(w, k, 0, sum(w)) def check(w, k, p1, p2): trunk_no = 1 temp = 0 m = 1+(p1 + p2)>>1 for i in w: if temp + i <= m: temp += i if temp==m: trunk_no+=1 temp = 0 else: trunk_no += 1 temp = i if trunk_no > k: return check(w, k, m, p2) else: if m - p2 == 0: return m return check(w, k, p1, m) if __name__=="__main__": n,k = map(int,input().split(" ")) w = [] for i in range(n): w.append(int(input())) print(min_sufficient_load(w,k))
s621986512
p02270
u005964097
1525952068
Python
Python3
py
Runtime Error
20
5600
655
def min_sufficient_load(w, k): return check(w, k, 0, sum(w)) def check(w, k, p1, p2): trunk_no = 1 temp = 0 m = 1+(p1 + p2)>>1 for i in w: if temp + i <= m: temp += i if temp==m: trunk_no+=1 temp = 0 else: trunk_no += 1 temp = i if trunk_no > k: return check(w, k, m, p2) else: if m - p1 == 1: return m return check(w, k, p1, m) if __name__=="__main__": n,k = map(int,input().split(" ")) w = [] for i in range(n): w.append(int(input())) print(min_sufficient_load(w,k))
s951921904
p02270
u005964097
1525952079
Python
Python3
py
Runtime Error
0
0
655
def min_sufficient_load(w, k): return check(w, k, 0, sum(w)) def check(w, k, p1, p2): trunk_no = 1 temp = 0 m = 1+(p1 + p2)>>1 for i in w: if temp + i <= m: temp += i if temp==m: trunk_no+=1 temp = 0 else: trunk_no += 1 temp = i if trunk_no > k: return check(w, k, m, p2) else: if m - p1 == 0: return m return check(w, k, p1, m) if __name__=="__main__": n,k = map(int,input().split(" ")) w = [] for i in range(n): w.append(int(input())) print(min_sufficient_load(w,k))
s422198263
p02270
u684241248
1527588366
Python
Python3
py
Runtime Error
190
5952
647
n, k = [int(_) for _ in input().split()] ary = [int(input()) for _ in range(n)] def search_v(p): v = 0 w = 0 tmp_k = 1 ind = 0 while True: if tmp_k > k: return v if ind == n: return n tmp = ary[ind] if w + tmp <= p: w += tmp v += 1 ind += 1 else: w = 0 tmp_k += 1 max_p = 10000 * 10000 ps = range(1, max_p) left = 0 right = max_p while left + 1 < right: mid = (left + right) // 2 v = search_v(ps[mid]) if v >= n: right = mid else: left = mid print(ps[right])
s478805389
p02270
u684241248
1527588469
Python
Python3
py
Runtime Error
20
5604
642
n, k = [int(_) for _ in input().split()] ary = [int(input()) for _ in range(n)] def search_v(p): v = 0 w = 0 tmp_k = 1 ind = 0 while True: if tmp_k > k: return v if ind == n: return n tmp = ary[ind] if w + tmp <= p: w += tmp v += 1 ind += 1 else: w = 0 tmp_k += 1 max_p = n * k ps = range(1, max_p + 1) left = 0 right = max_p while left + 1 < right: mid = (left + right) // 2 v = search_v(ps[mid]) if v >= n: right = mid else: left = mid print(ps[right])
s035255242
p02270
u986478725
1527656378
Python
Python3
py
Runtime Error
370
7528
1168
# ALDS1_4_D. # アロケーション。 W = [0 for i in range(100000)] def intinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def canLoad(P, n, k): # P以下の条件下ですべての荷物を積めるか否か。 # Wには荷物の情報が入ってる。nは荷物の個数、kはトラックの台数。 # i > nで返ればTrue. sumOfLoad = 0 numOfPackage = 0 numOfTrack = 1 while numOfPackage <= n: sumOfLoad += W[numOfPackage] if sumOfLoad > P: sumOfLoad = 0; numOfTrack += 1 else: numOfPackage += 1 if numOfTrack > k: break if numOfPackage > n: return True # 全部積めた場合。 return False def main(): data = intinput() n = data[0]; k = data[1] for i in range(n): W[i] = int(input()) left = 0; right = 10000 * 100000 # leftは0から始まり常に満たさない側、rightは常に満たす側。 while right - left > 1: mid = (left + right) // 2 if canLoad(mid, n, k): right = mid else: left = mid print(right) if __name__ == "__main__": main()
s839011165
p02270
u436634575
1400893808
Python
Python3
py
Runtime Error
0
0
471
def check(p): s = w[0] track = 1 for i in range(1, n): if s + w[i] <= p: s += w[i] else: track += 1 if track > k: return False s = w[i] return True n, k = map(int, input().strip().split()) w = [] for i in range(n): w.append(int(input())) L = max(w) if check(L): return L R = sum(w) while L + 1 < R: M = (L + R) // 2 if check(M): R = M else: L = M print(R)
s517762655
p02271
u657361950
1530970150
Python
Python3
py
Runtime Error
13690
5608
423
def solve(a, m): return solve_(a, 0, m) def solve_(a, i, m): res = False if m == 0: res = True elif i >= len(a): res = False else: res1 = solve_(a, i + 1, m) res2 = solve_(a, i + 1, m - a[i]) res = res1 or res2 return res n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for i in range(q): if solve(a, m[i]): print('yes') else: print('no')
s153290246
p02271
u153665391
1531061379
Python
Python3
py
Runtime Error
3220
5612
630
N = int(input()) A = sorted(list(map(int, input().split()))) Q = int(input()) M = list(map(int, input().split())) def exhastive_search(target, head, sum): for i in range(head, N): sum += A[i] if target == sum: return True elif target > sum: if exhastive_search(target, i+1, sum): return True else: return False sum -= A[i] return False for target in M: head = 0 sum = 0 result = "no" for i in range(N): if exhastive_search(target, i, sum): result = "yes" break print(result)
s805049719
p02271
u153665391
1531061673
Python
Python3
py
Runtime Error
3200
5608
617
N = int(input()) A = sorted(list(map(int, input().split()))) Q = int(input()) M = list(map(int, input().split())) def exhastive_search(target, head, sum): for i in range(head, N): sum += A[i] if target == sum: return True elif target > sum: if exhastive_search(target, i+1, sum): return True else: return False sum -= A[i] return False for target in M: sum = 0 result = "no" for i in range(N): if exhastive_search(target, i, sum): result = "yes" break print(result)
s609081576
p02271
u153665391
1531103004
Python
Python3
py
Runtime Error
3200
5612
612
N = int(input()) A = list(map(int, input().split())) Q = int(input()) M = list(map(int, input().split())) def exhastive_search(target, head, sum): for i in range(head, N): sum += A[i] if target == sum: return True elif target > sum: if exhastive_search(target, i+1, sum): return True sum -= A[i] else: sum -= A[i] return False for target in M: sum = 0 result = "no" for i in range(N): if exhastive_search(target, i, sum): result = "yes" break print(result)
s823017417
p02271
u153665391
1531103521
Python
Python3
py
Runtime Error
3180
5608
621
N = int(input()) A = sorted(list(map(int, input().split()))) Q = int(input()) M = list(map(int, input().split())) def exhastive_search(target, head, sum): for i in range(head, N): sum += A[i] if target == sum: return True elif target > sum: if exhastive_search(target, i+1, sum): return True sum -= A[i] else: return False return False for target in M: sum = 0 result = "no" for i in range(N): if exhastive_search(target, i, sum): result = "yes" break print(result)
s832860466
p02271
u153665391
1531104099
Python
Python3
py
Runtime Error
3290
5608
691
N = int(input()) A = sorted(list(map(int, input().split()))) Q = int(input()) M = list(map(int, input().split())) def exhastive_search(target, head, sum): for i in range(head, N): sum += A[i] if target == sum: return True elif target > sum: if exhastive_search(target, i+1, sum): return True sum -= A[i] else: return False return False for target in M: sum = 0 result = "no" for i in range(N): if target < A[i]: break else: if exhastive_search(target, i, sum): result = "yes" break print(result)
s219444381
p02271
u153665391
1531214482
Python
Python3
py
Runtime Error
8210
5612
401
N = int(input()) A = list(map(int, input().split())) Q = int(input()) M = list(map(int, input().split())) def solve(idx, target): if target == 0: return True if idx >= N: return False if solve(idx+1, target) or solve(idx+1, target-A[idx]): return True return False for target in M: if solve(0, target): print("yes") else: print("no")
s109232328
p02271
u153665391
1531215205
Python
Python3
py
Runtime Error
9250
5612
451
N = int(input()) A = sorted(list(map(int, input().split()))) Q = int(input()) M = list(map(int, input().split())) def solve(idx, target): if target == 0: return True elif target < 0: return False if idx >= N: return False if solve(idx+1, target) or solve(idx+1, target-A[idx]): return True return False for target in M: if solve(0, target): print("yes") else: print("no")
s571492788
p02271
u316584871
1531287684
Python
Python3
py
Runtime Error
13830
7036
365
n = int(input()) seq = list(map(int, input().split())) q = int(input()) mlist = list(map(int, input().split())) def check(i, m): if m == 0: return 'yes' elif i >= n: return 'no' res = check(i+1, m) + check(i+1, m - seq[i]) return res for m in mlist: if('yes' in check(0, m)): print('yes') else: print('no')
s278343865
p02271
u316584871
1531287853
Python
Python3
py
Runtime Error
11600
5612
352
n = int(input()) seq = list(map(int, input().split())) q = int(input()) mlist = list(map(int, input().split())) def check(i, m): if m == 0: return 1 elif i >= n: return 0 res = check(i+1, m) + check(i+1, m - seq[i]) return res for m in mlist: if(check(0,m) > 0): print('yes') else: print('no')
s924727950
p02271
u316584871
1531288128
Python
Python3
py
Runtime Error
11640
5612
355
n = int(input()) seq = list(map(int, input().split())) q = int(input()) mlist = list(map(int, input().split())) def check(i, m): if m == 0: return True elif i >= n: return False res = check(i+1, m) + check(i+1, m - seq[i]) return res for m in mlist: if(check(0,m)): print('yes') else: print('no')
s228136819
p02271
u316584871
1531288737
Python
Python3
py
Runtime Error
11830
5612
466
n = int(input()) seq = list(map(int, input().split())) q = int(input()) mlist = list(map(int, input().split())) global mins mins = min(seq) global sums sums = sum(mlist) def check(i, m): if m == 0: return True elif i >= n: return False res = check(i+1, m) + check(i+1, m - seq[i]) return res for m in mlist: if (mins > m or sums < m): print('no') elif(check(0,m)): print('yes') else: print('no')
s208138380
p02271
u316584871
1531288971
Python
Python3
py
Runtime Error
3010
5608
485
n = int(input()) seq = list(map(int, input().split())) q = int(input()) mlist = list(map(int, input().split())) global mins mins = min(seq) sums = 0 for a in seq: sums += a def check(i, m): if m == 0: return True elif i >= n or mins > m: return False res = check(i+1, m) + check(i+1, m - seq[i]) return res for m in mlist: if (mins > m or sums < m): print('no') elif(check(0,m)): print('yes') else: print('no')
s812429046
p02271
u316584871
1531289455
Python
Python3
py
Runtime Error
2770
5612
489
n = int(input()) seq = list(map(int, input().split())) q = int(input()) mlist = list(map(int, input().split())) mins = min(seq) sums = 0 for a in seq: sums += a def check(i, m): global mins if m == 0: return True elif i >= n or mins > m: return False res = check(i+1, m) + check(i+1, m - seq[i]) return res for m in mlist: if (mins > m or sums < m): print('no') elif(check(0,m)): print('yes') else: print('no')
s071810765
p02271
u094978706
1535699112
Python
Python3
py
Runtime Error
0
0
574
import numpy as np n = int(input()) A = np.array(list(map(int, input().split() ))) q = int(input()) m = list(map(int, input().split())) def deci_to_bin_list(num, n): out = np.zeros(n, dtype='int') for i in range(n-1, -1, -1): denom = 2**i out[i] = num // denom num = num % denom return out def sums_to_num(A, num): n = len(A) for cnt in range(2**n - 1): selected = deci_to_bin_list(cnt, n) if np.sum(A*selected) == num: return 'yes' return 'no' for num in m: print(sums_to_num(A, num))
s333414324
p02271
u580607517
1421035959
Python
Python
py
Runtime Error
0
0
308
def solve(i, m): if i >= n: return m == 0 if solve(i + 1, m): return True if solve(i + 1, m - A[i]): return True return False n = int(raw_input()) A = map(int,raw_input().split()) q = int(raw_input()) for i in xrange(q): m = int(raw_input()) if solve(0, m): print "yes" else: print "no"
s655861556
p02271
u580607517
1421036202
Python
Python
py
Runtime Error
19930
4220
311
def solve(i, m): if i >= n: return m == 0 if solve(i + 1, m): return True if solve(i + 1, m - A[i]): return True return False n = int(raw_input()) A = map(int,raw_input().split()) q = int(raw_input()) M = map(int, raw_input().split()) for m in M: if solve(0, m): print "yes" else: print "no"
s179639023
p02271
u580607517
1421036278
Python
Python
py
Runtime Error
19930
4220
311
def solve(i, m): if i >= n: return m == 0 if solve(i + 1, m): return True if solve(i + 1, m - A[i]): return True return False n = int(raw_input()) A = map(int,raw_input().split()) q = int(raw_input()) M = map(int, raw_input().split()) for m in M: if solve(0, m): print "yes" else: print "no"
s619722506
p02271
u567380442
1421406052
Python
Python3
py
Runtime Error
0
0
251
n = input() a = list(map(int, input().split())) q = input() aset = set() for i in range(1, len(a) + 1): aset |= set(sum(combi) for combi in itertools.combinations(a, i)) for m in map(int, input().split()): print('yes' if m in aset else 'no')
s692542768
p02271
u879226672
1427351875
Python
Python
py
Runtime Error
19930
74512
446
n = int(raw_input()) A = map(int,raw_input().split()) q = int(raw_input()) mi = map(int,raw_input().split()) S = [] for k in range(1,2**len(A)): S.append(map(int,list((format(k,'b').zfill(len(A)))))) for m in mi: for k in range(len(S)): tot = 0 for j in range(len(S[k])): if S[k][j]: tot += A[j] if m == tot: print 'yes' break else: print 'no'
s633381200
p02271
u879226672
1430836835
Python
Python
py
Runtime Error
19930
66172
449
n = int(raw_input()) A = map(int,raw_input().split()) q = int(raw_input()) mi = map(int,raw_input().split()) S = [] for k in xrange(1,2**len(A)): S.append(map(int,list((format(k,'b').zfill(len(A)))))) for m in mi: for k in xrange(len(S)): tot = 0 for j in xrange(len(S[k])): if S[k][j]: tot += A[j] if m == tot: print 'yes' break else: print 'no'
s675089109
p02271
u689297737
1432860481
Python
Python
py
Runtime Error
19930
4240
788
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_A # Exhaustive Search # Result: import sys def calc(target, cur_sum, ary, ary_idx): new_sum = cur_sum + ary[ary_idx] if new_sum == target: return True ary_idx += 1 if ary_idx == len(ary): return False return calc(target, cur_sum, ary, ary_idx) or \ calc(target, new_sum, ary, ary_idx) ### main nums_len = int(sys.stdin.readline().rstrip()) nums = [int(x) for x in sys.stdin.readline().rstrip().split(' ')] assert len(nums) == nums_len vals_len = int(sys.stdin.readline().rstrip()) vals = [int(x) for x in sys.stdin.readline().rstrip().split(' ')] assert len(vals) == vals_len for val in vals: if calc(val, 0, nums, 0): print 'yes' else: print 'no'
s487105985
p02271
u140201022
1434385981
Python
Python
py
Runtime Error
19930
4240
534
n=int(raw_input()) a=map(int,raw_input().split()) q=int(raw_input()) m=map(int,raw_input().split()) ans=chk=0 bits=(1<<n)-1 for i in m: p=bits flag=0 while p: chk=str(bin(p))[2:] chk='0'*(n-len(chk))+chk p-=1 h=0 for j,k in enumerate(chk): if k=='1': h+=a[j] if h==i: print 'yes' p=0 flag=1 continue elif h>i: break if flag==0: print 'no'
s421903282
p02271
u604774382
1437313345
Python
Python
py
Runtime Error
0
0
392
def solve( p, t ): global isExist global n global A isExist[ t ] = True if p < n: solve( p+1, t-A[p] ) solve( p+1, t ) isExist = [False]*2001 n = int( raw_input() ) A = map( int, raw_input().split( " " ) ) q = int( raw_input() ) M = map( int, raw_input().split( " " ) ) s = sum( A ) solve( 0, s ) for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
s215680089
p02271
u604774382
1437313504
Python
Python3
py
Runtime Error
0
0
376
def solve( p, t ): global isExist global n global A isExist[ t ] = True if p < n: solve( p+1, t-A[p] ) solve( p+1, t ) isExist = [False]*2001 n = int( input() ) A = map( int, input().split( " " ) ) q = int( input() ) M = map( int, input().split( " " ) ) s = sum( A ) solve( 0, s ) for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
s282138191
p02271
u604774382
1437313781
Python
Python3
py
Runtime Error
0
0
404
def solve( p, t ): global isExist global n global A isExist[ t ] = True if p < n: solve( p+1, t-A[p] ) solve( p+1, t ) isExist = [False]*2001 n = int( input() ) A = [ int( val ) for val in input().split( " " ) ] q = int( input() ) M = [ int( val ) for val in input().split( " " ) ] s = sum( A ) solve( 0, s ) for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
s608212315
p02271
u604774382
1437313957
Python
Python
py
Runtime Error
0
0
437
def solve( p, t ): global isExist global n global A isExist[ t ] = True if p < n: solve( p+1, t-A[p] ) solve( p+1, t ) else: return isExist = [False]*2001 n = int( raw_input() ) A = [ int( val ) for val in raw_input().split( ' ' ) ] q = int( raw_input() ) M = [ int( val ) for val in raw_input().split( ' ' ) ] s = sum( A ) solve( 0, s ) for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
s763891215
p02271
u604774382
1437314368
Python
Python
py
Runtime Error
0
0
373
isExist = [False]*2001 n = int( raw_input() ) A = [ int( val ) for val in raw_input().split( ' ' ) ] for i in A: for j in range( 2000-i, 0, -1 ): if isExist[j]: isExist[ i+j ] = True isExist[i] = True q = int( raw_input() ) M = [ int( val ) for val in raw_input().split( ' ' ) ] for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
s590375542
p02271
u604774382
1437314430
Python
Python3
py
Runtime Error
0
0
357
isExist = [False]*2001 n = int( input() ) A = [ int( val ) for val in input().split( ' ' ) ] for i in A: for j in range( 2000-i, 0, -1 ): if isExist[j]: isExist[ i+j ] = True isExist[i] = True q = int( input() ) M = [ int( val ) for val in input().split( ' ' ) ] for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
s064432568
p02271
u604774382
1437315348
Python
Python3
py
Runtime Error
0
0
204
isExist = [False]*2001 n = int( input() ) A = [ int( val ) for val in input().split( ' ' ) ] q = int( input() ) M = [ int( val ) for val in input().split( ' ' ) ] for i in range( 0, q ): print( "yes" )
s821408640
p02271
u604774382
1437315374
Python
Python3
py
Runtime Error
0
0
179
n = int( input() ) A = [ int( val ) for val in input().split( ' ' ) ] q = int( input() ) M = [ int( val ) for val in input().split( ' ' ) ] for i in range( 0, q ): print( "yes" )
s557574965
p02271
u604774382
1437315490
Python
Python3
py
Runtime Error
0
0
179
d = int( input() ) c = [ int( val ) for val in input().split( " " ) ] f = int( input() ) b = [ int( val ) for val in input().split( " " ) ] for i in range( 0, 3 ): print( "yes" )