input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
N, K = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) F = tuple(map(int, input().split())) def can_eat(t): F_time = sorted([t // f for f in F]) training = 0 for i in range(N): training += max(0, A[i] - F_time[i]) return training <= K # bisect l, r = -1, 10 ** 12 while r - l > 1: m = (r + l) // 2 if can_eat(m): r = m else: l = m print(r)
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) F = tuple(map(int, input().split())) def can_eat(t): F_time = sorted([t // f for f in F]) training = 0 for i in range(N): training += max(0, A[i] - F_time[i]) return training <= K # bisect l, r = -1, 10 ** 12 while r - l > 1: m = (r + l) // 2 if can_eat(m): r = m else: l = m print(r)
p02883
import heapq class Heapq: def __init__(self, arr, desc=False): if desc: arr = [-a for a in arr] self.sign = -1 if desc else 1 self.hq = arr heapq.heapify(self.hq) def pop(self): return heapq.heappop(self.hq) * self.sign def push(self, a): heapq.heappush(self.hq, a * self.sign) def top(self): return self.hq[0] * self.sign def resolve(): n,k = list(map(int,input().split())) member_cost = list(map(int,input().split())) food_cost = list(map(int,input().split())) member_cost.sort() food_cost.sort(reverse=True) total_cost = [] for i in range(len(member_cost)): total_cost.append(member_cost[i]*food_cost[i]) total_cost_heap = Heapq(total_cost,True) if k >= sum(member_cost): print((0)) else: while k > 0: k -= 1 max_cost = total_cost_heap.pop() reduce_index = total_cost.index(max_cost) member_cost[reduce_index] -= 1 total_cost[reduce_index] -= food_cost[reduce_index] total_cost_heap.push(total_cost[reduce_index]) print((max(total_cost))) resolve()
class Contest: def __init__(self, member_cost,food_cost,k): self.member_cost = member_cost self.food_cost = food_cost self.max_training_times = k def canAchieve(self,target): sum_training_times = 0 for i in range(len(self.member_cost)): sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i]) return sum_training_times <= self.max_training_times def bisect(self,begin,end): if (end - begin <= 1 ): return end target = (begin + end)//2 if self.canAchieve(target): return self.bisect(begin,target) else: return self.bisect(target,end) def resolve(): n,k = list(map(int,input().split())) member_cost = list(map(int,input().split())) food_cost = list(map(int,input().split())) member_cost.sort() food_cost.sort(reverse=True) total_cost = [] for i in range(len(member_cost)): total_cost.append(member_cost[i]*food_cost[i]) max_total_cost = max(total_cost) contest = Contest(member_cost,food_cost,k) print((contest.bisect(-1,max_total_cost))) resolve()
p02883
import heapq import bisect N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) F = sorted(F, reverse = True) A = sorted(A) flg = 0 lst = [] for i in range(N): if A[i] == 0 or F[i] == 0: break else: lst.insert(bisect.bisect_left(lst, [A[i] * F[i], F[i]]),[A[i] * F[i], F[i]]) # heapq.heappush(heap, [- A[i] * F[i], F[i]]) for i in range(K): popped = lst.pop(-1) popped[0] -= popped[1] lst.insert(bisect.bisect_left(lst, popped), popped) print((lst[-1][0]))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse = True) ng = -1 ok = 10 ** 12 while ok - ng > 1: mid = (ok + ng) // 2 ctr = 0 for i in range(N): ctr += max(0, A[i] - mid // F[i]) if ctr <= K: ok = mid else: ng = mid print(ok)
p02883
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def bisearch_min(mn, mx, func): """ 条件を満たす最小値を見つける二分探索 """ ok = mx ng = mn while ng+1 < ok: mid = (ok+ng) // 2 if func(mid): # 下を探しに行く ok = mid else: # 上を探しに行く ng = mid return ok N, K = MAP() A = LIST() B = LIST() A.sort(reverse=True) B.sort() def check(m): k = 0 for i, a in enumerate(A): b = B[i] k += max(ceil(a - m/b), 0) if k > K: return False return True print((bisearch_min(-1, INF, check)))
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def bisearch_min(mn, mx, func): """ 条件を満たす最小値を見つける二分探索 """ ok = mx ng = mn while ng+1 < ok: mid = (ok+ng) // 2 if func(mid): # 下を探しに行く ok = mid else: # 上を探しに行く ng = mid return ok N, K = MAP() A = LIST() B = LIST() A.sort(reverse=True) B.sort() def check(m): k = 0 for i, a in enumerate(A): b = B[i] k += max(ceil(a - m/b), 0) if k > K: return False return True print((bisearch_min(-1, 10**12, check)))
p02883
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort(reverse=True) la = 10**6+1 cnt = [0] * la for u in a: cnt[u] += 1 for i in range(1, la): cnt[i] += cnt[i-1] def judge(x): y = k for i in range(n): goal = x//f[i] if a[i] > goal: y -= a[i] - goal if y < 0: return False return y >= 0 left = -1 right = 10**12 + 1 while left + 1 < right: mid = (left + right)//2 if judge(mid): right = mid else: left = mid print(right)
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort(reverse=True) def judge(x): y = k for i in range(n): goal = x//f[i] if a[i] > goal: y -= a[i] - goal if y < 0: return False return y >= 0 left = -1 right = 10**12 + 1 while left + 1 < right: mid = (left + right)//2 if judge(mid): right = mid else: left = mid print(right)
p02883
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(eval(input())) NMI = lambda: list(map(int, input().split())) NLI = lambda: list(NMI()) SI = lambda: eval(input()) def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] def main(): N, K = NMI() A = NLI() F = NLI() A.sort() ok = 10**13 ng = 0 for i in range(100): mid = (ok+ng) // 2 limits = [mid//f for f in F] limits.sort() ks = [max(a-l, 0) for a, l in zip(A, limits)] if sum(ks) <= K: ok = mid else: ng = mid print(ok) if __name__ == "__main__": main()
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(eval(input())) NMI = lambda: list(map(int, input().split())) NLI = lambda: list(NMI()) SI = lambda: eval(input()) def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] def main(): N, K = NMI() A = NLI() F = NLI() A.sort() F.sort(reverse=True) ok = 10**13 ng = 0 for i in range(100): mid = (ok+ng) // 2 limits = [mid//f for f in F] ks = [max(a-l, 0) for a, l in zip(A, limits)] if sum(ks) <= K: ok = mid else: ng = mid print(ok) if __name__ == "__main__": main()
p02883
import sys from bisect import bisect_left def solve(): input = sys.stdin.readline N, K = list(map(int, input().split())) A = [int(a) for a in input().split()] F = [int(f) for f in input().split()] A.sort(reverse = True) F.sort() low, high = -1, 10 ** 12 + 1 while high - low > 1: mid = (low + high) // 2 count = 0 for i in range(N): if A[i] * F[i] > mid: count += A[i] - (mid // F[i]) if count > K: low = mid else: high = mid print(high) return 0 if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline N, K = list(map(int, input().split())) A = [int(a) for a in input().split()] F = [int(f) for f in input().split()] A.sort(reverse = True) F.sort() low, high = -1, 10 ** 12 + 1 while high - low > 1: mid = (low + high) // 2 count = 0 for i in range(N): if A[i] * F[i] > mid: count += A[i] - (mid // F[i]) if count > K: low = mid else: high = mid print(high) return 0 if __name__ == "__main__": solve()
p02883
import heapq n,k = list(map(int,input().split())) a = list(map(int,input().split())) f = list(map(int,input().split())) hq = [] a.sort() f.sort(reverse = True) for i in range(n): heapq.heappush(hq, (-a[i]*f[i], a[i], f[i])) for i in range(k): s,a1,f1 = heapq.heappop(hq) if s == 0: print((0)) exit() a1 -= 1 heapq.heappush(hq, (-a1*f1, a1, f1)) print((-heapq.heappop(hq)[0]))
n,k = list(map(int,input().split())) a = list(map(int,input().split())) f = list(map(int,input().split())) def hantei(c): tmp = 0 for i in range(n): if af[i] > c: a1 = c // f[i] tmp += a[i]- a1 if tmp <= k: return True else: return False hq = [] a.sort() f.sort(reverse = True) af = [] for i in range(n): af.append(a[i] * f[i]) l = 0 r = 10**12+10 while r - l > 1: c = (l + r) // 2 if hantei(c): r = c else: l = c if hantei(l): print(l) else: print(r)
p02883
from heapq import heappop, heappush N, K = list(map(int, input().split())) digests = list(map(int, input().split())) foods = list(map(int, input().split())) foods.sort() digests.sort(reverse=True) hq = [] for i in range(N): heappush(hq, (-digests[i]*foods[i], digests[i], foods[i])) for _ in range(K): cost, digest, food = heappop(hq) if cost == 0: heappush(hq, (0, 0, 0)) break heappush(hq, (-(digest-1)*food, digest-1, food)) ans = 0 max_c, digest, food = heappop(hq) print((-max_c))
N, K = list(map(int, input().split())) costs = list(map(int, input().split())) foods = list(map(int, input().split())) foods.sort() costs.sort(reverse=True) def can_eat(x): count = 0 for i in range(N): count += max(0, costs[i]-x//foods[i]) return count <= K l, r = -1, 10**12+1 while r-l > 1: mid = (l+r)//2 if can_eat(mid): r = mid else: l = mid print(r)
p02883
#設定 import sys input = sys.stdin.buffer.readline from heapq import heappop, heappush INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N, K = getlist() A = getlist() F = getlist() A = sorted(A) F = sorted(F) Q = [] for i in range(N): heappush(Q, [ (-A[i]) * F[N - 1 - i], -A[i], -F[N - 1 - i]]) #print(Q) #処理 for i in range(K): if Q[0][0] == 0: break else: s, a, f = heappop(Q) a += 1 s = -(a * f) heappush(Q, [s, a, f]) #print(Q) ans = 0 for i in range(N): ans = max(ans, -Q[i][0]) print(ans) if __name__ == '__main__': main()
#設定 import sys input = sys.stdin.buffer.readline INF = float("inf") def getlist(): return list(map(int, input().split())) #二分探索基本形 L:リスト x:値 n:リスト長 def Binary_Search(A, F, N, K): #初期化 left = 0 right = 10 ** 12 ans = INF #二分探索 while left <= right: mid = (left + right) // 2 cnt = 0 for i in range(N): if A[i] * F[i] > mid: cnt += (A[i] - int(mid // F[i])) if cnt <= K: right = mid - 1 ans = min(ans, mid) else: left = mid + 1 return ans #処理内容 def main(): N, K = getlist() A = getlist() F = getlist() A = sorted(A) F = sorted(F)[::-1] ans = Binary_Search(A, F, N, K) print(ans) if __name__ == '__main__': main()
p02883
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) if K >= sum(A): print((0)) exit() A.sort(reverse=True) F.sort() #print('A:', A) #print('F:', F) res = K lot = [A[k]*F[k] for k in range(N)] #print(lot) #print(res) now = [] for k in range(N): now.append((-lot[k], k)) from heapq import heapify, heappop, heappush from math import ceil heapify(now) #print(now) f = heappop(now) while res>0: #print(res) #print(now) s = heappop(now) big = lot[f[1]] small = lot[s[1]] cnt = ceil((big-small)/F[f[1]]) if big == small: cnt = 1 if cnt > A[f[1]]: print((lot[f[1]] - A[f[1]]*F[f[1]])) exit() if cnt >= res: lot[f[1]] -= res*F[f[1]] break else: lot[f[1]] -= cnt*F[f[1]] A[f[1]] -= cnt res -= cnt heappush(now, (-lot[f[1]], f[1])) f = s print((max(lot)))
from math import ceil N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) if K >= sum(A): print((0)) exit() A.sort(reverse=True) F.sort() lot = [] for k in range(N): lot.append((A[k]*F[k], k)) lot.sort(key = lambda x:x[0],reverse=True) high = lot[0][0] #print('A:', A) #print('F:', F) #rint(lot) def binary_search(high): low = 0 mid = (low + high) //2 while low < high: final = False mid = (low + high) //2 #print(low, high, mid) if low == high-1: final = True #print(low, high, mid) res = K flag = True for k in range(N): if res < 0: break else: if lot[k][0] <= mid: break else: res -= ceil((lot[k][0]-mid)/F[lot[k][1]]) continue if res < 0: flag = False #print(flag) if flag: high = mid else: if final: mid += 1 low = mid #print(low, high, mid) #return None return mid print((binary_search(high)))
p02883
import math import sys MAX_INT = int(10e15) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) def judge(x): cnt = 0 for i in range(N): tmp = a[i] - x//f[i] cnt += max(tmp, 0) else: if cnt <= K: return True else: return False # 二分探索 # def nibutan(): # MAX(A*F) ans left = -1 ans = num while left+1 != ans: middle = (left+ans)//2 if judge(middle): ans = middle else: left = middle return ans N, K = IL() a = IL() f = IL() a.sort() f.sort(reverse=True) num = 0 for i in range(N): num = max(num, a[i]*f[i]) print((nibutan()))
import sys MAX_INT = int(10e15) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return eval(input()) def judge(x): cnt = 0 for i in range(N): tmp = a[i] - x//f[i] cnt += max(tmp, 0) else: if cnt <= K: return True else: return False # 二分探索 # def nibutan(): # MAX(A*F) ans left = -1 ans = num while left+1 != ans: middle = (left+ans)//2 if judge(middle): ans = middle else: left = middle return ans N, K = IL() a = IL() f = IL() a.sort() f.sort(reverse=True) num = 0 for i in range(N): num = max(num, a[i]*f[i]) print((nibutan()))
p02883
import math N,K = list(map(int,input().split())) A = sorted(list(map(int,input().split()))) F = sorted(list(map(int,input().split())),reverse=True) high = 0 for i in range(N): high = max(high,A[i]*F[i]) low = -1 while high-low>1: mid = (high+low)//2 flag = 1 T = K for i in range(N): if A[i]*F[i]<=mid:continue else: T -= math.ceil(A[i]-mid/F[i]) if T<0: flag = 0 break if flag==1: high = mid else: low = mid print(high)
N,K = list(map(int,input().split())) A = sorted(list(map(int,input().split()))) F = sorted(list(map(int,input().split())),reverse=True) if K>=sum(A): ans = 0 else: low = 0 high = 10**12 while high-low>1: mid = (high+low)//2 B = A[:] cnt = 0 for i in range(N): if B[i]*F[i]>mid: cnt += (B[i]-mid//F[i]) if cnt<=K: high = mid else: low = mid ans = high print(ans)
p02883
def main(): n, k = list(map(int, input().split())) *a, = list(map(int, input().split())) *f, = list(map(int, input().split())) a.sort() f.sort(reverse=1) prod = [(y, x * y) for x, y in zip(a, f)] l = -1 r = 10 ** 12 while r - l > 1: m = (l + r) // 2 s = sum(max(0, 0 - (m - p) // y) for y, p in prod) if s <= k: r = m else: l = m print(r) if __name__ == "__main__": main()
def main(): n, k = list(map(int, input().split())) *a, = list(map(int, input().split())) *f, = list(map(int, input().split())) a.sort() f.sort(reverse=True) prod = sorted([(x * y, y) for x, y in zip(a, f)], reverse=True) + [(0, -1)] l = -1 r = 10 ** 12 while r - l > 1: m = (l + r) // 2 s = 0 for p, y in prod: if p <= m: r = m break s += 0 - (m - p) // y if s > k: l = m break print(r) if __name__ == "__main__": main()
p02883
import math n, k = list(map(int, input().split())) # a = [int(x) for x in input().split()] # f = [int(x) for x in input().split()] a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort(reverse=True) lx = 0 rx = a[-1] * f[0] for i in range(1000): if lx == rx: break cx = (lx + rx) // 2 kk = 0 for j in range(n): ta = a[j] y = (ta*f[j] - cx + f[j] -1) // f[j] kk += max(0, y) if kk <= k: rx = cx else: lx = cx print(rx)
n, k = list(map(int, input().split())) # a = [int(x) for x in input().split()] # f = [int(x) for x in input().split()] a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort(reverse=True) lx = -1 rx = a[-1] * f[0] while rx-lx>1 : cx = (lx + rx) // 2 kk = 0 for j in range(n): kk += max(0, a[j] - cx//f[j]) if kk <= k: rx = cx else: lx = cx print(rx)
p02883
import copy import math n, k = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort() A.reverse() maxX = max(F) * max(A) x = [-1 for i in range(maxX + 1)] def is_able(low, up): target = (low + up) // 2 if low == up - 1: return up if check(target): x[target] = 1 return is_able(low, target) else: x[target] = 0 return is_able(target, up) def check(time): #time が可能かどうか practice = copy.deepcopy(k) for i in range(n): if A[i] * F[i] > time: practice -= A[i] - math.floor(time / F[i]) if practice < 0: return False return True x[0] = int(check(0)) x[maxX] = int(check(maxX)) print((is_able(-1, maxX)))
import copy import math n, k = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort() A.reverse() maxX = max(F) * max(A) def is_able(low, up): target = (low + up) // 2 if low == up - 1: return up if check(target): return is_able(low, target) else: return is_able(target, up) def check(time): #time が可能かどうか practice = copy.deepcopy(k) for i in range(n): if A[i] * F[i] > time: practice -= A[i] - math.floor(time / F[i]) if practice < 0: return False return True print((is_able(-1, maxX)))
p02883
import heapq n,k=list(map(int,input().split())) a=sorted(list(map(int,input().split()))) f=sorted(list(map(int,input().split())),reverse=True) d=[[-a[i]*f[i],f[i]] for i in range(n)] d.sort(key=lambda x:x[0]) heapq.heapify(d) for _ in range(k): i,j=heapq.heappop(d) i+=j heapq.heappush(d,[i,j]) ans,_=heapq.heappop(d) print((max(ans*(-1),0)))
n,k=list(map(int,input().split())) a=sorted(list(map(int,input().split()))) f=sorted(list(map(int,input().split())),reverse=True) d=[[a[i]*f[i],f[i]] for i in range(n)] r=max([di[0] for di in d])+1 l=0 x=(l+r)//2 while r-l>1: if r-l==2: cnt=0 for di,fi in d: cnt+=max(0,(di-l+fi-1)//fi) if cnt<=k: x=l else: x=l+1 break cnt=0 for di,fi in d: cnt+=max(0,(di-x+fi-1)//fi) if cnt>k: l,r=x,r else: l,r=l,x+1 x=(l+r)//2 if r-l==2: if cnt>k: x=l+1 else: x=l print(x)
p02883
N,K = list(map(int,input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) if sum(A) <= K: print((0)) exit() A.sort() F.sort(reverse=True) def check(x): k = 0 for a,f in zip(A, F): if a*f > x: while a > 0: a -= 1 k += 1 if a*f <= x: break return k <= K # AをX以下にできるか?? ng,ok = 0, 10**18+1 while ok-ng > 1: x = (ok+ng)//2 if check(x): ok = x else: ng = x print(ok)
N,K = list(map(int,input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) if sum(A) <= K: print((0)) exit() A.sort() F.sort(reverse=True) def check(x): k = 0 for a,f in zip(A, F): k += max(0, a-(x//f)) return k <= K # AをX以下にできるか?? ng,ok = 0, 10**18+1 while ok-ng > 1: x = (ok+ng)//2 if check(x): ok = x else: ng = x print(ok)
p02883
from heapq import heappush, heappushpop, heappop N, K = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) F = list(map(int, input().split())) A.sort() F.sort() hq = [] for a, f in zip(A, F): heappush(hq, (a * f, f)) c, f = heappop(hq) while K > 0: c += f K -= 1 c, f = heappushpop(hq, (c, f)) print((-c))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort(reverse=True) F.sort() C = [None] * N for i, (a, f) in enumerate(zip(A, F)): C[i] = (a * f, f) def solve(x): global K, N t = 0 for c, f in C: temp = ((c - x) + f - 1) // f t += max(0, temp) if t > K: result = False break else: result = True return result ok = A[0] * F[N - 1] ng = -1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid print(ok)
p02883
def solve(mid): l=k for b,g in zip(a,f): if b*g>mid: l-=b-mid//g if l<0:return False return True n,k,*a=list(map(int,open(0).read().split())) a,f=sorted(a[:n])[::-1],sorted(a[n:]) ok=10**12 ng=-1 while abs(ok-ng)>1: mid=(ok+ng)//2 if solve(mid): ok=mid else: ng=mid print(ok)
def main(): n,k,*a=list(map(int,open(0).read().split())) a,f=sorted(a[:n])[::-1],sorted(a[n:]) ok=10**12 ng=-1 while abs(ok-ng)>1: mid=(ok+ng)//2 l=k for b,g in zip(a,f): if b*g>mid: l-=b-mid//g if l<0:ng=mid else:ok=mid print(ok) main()
p02883
def main(): n,k,*a=list(map(int,open(0).read().split())) a,f=sorted(a[:n]),sorted(a[n:],reverse=1) ok=10**12 ng=-1 while ok-ng>1: mid=(ok+ng)//2 l=k for b,g in zip(a,f): if b*g>mid:l-=b-mid//g if l<0:ng=mid else:ok=mid print(ok) main()
def main(): n,k,*a=list(map(int,open(0).read().split())) a,f=sorted(a[:n]),sorted(a[n:],reverse=1) ok=10**12 ng=-1 while ok-ng>1: mid=(ok+ng)//2 l=k for b,g in zip(a,f): t=b-mid//g if t>0:l-=t if l<0:ng=mid else:ok=mid print(ok) main()
p02883
n,k,*a=list(map(int,open(0).read().split())) z=sorted(a[:n]),sorted(a[n:])[::-1] o=10**12 g=-1 while o-g>1: m,l=o+g>>1,k for a,f in zip(*z):l-=max(0,a-m//f) if l<0:g=m else:o=m print(o)
i,s=lambda:list(map(int,input().split())),sorted n,k=i() z=s(i()),s(i())[::-1] o=10**12 g=-1 while o-g>1: m,l=o+g>>1,k for a,f in zip(*z):l-=max(0,a-m//f) if l<0:g=m else:o=m print(o)
p02883
N,K = list(map(int,input().split())) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) ng = -1 ok = 10**18 while ok - ng > 1: mid = (ok + ng) // 2 c = 0 for i in range(N): c += max(0,A[i]-mid//F[i]) if c <= K: ok = mid else: ng = mid print(ok)
N,K = list(map(int,input().split())) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) ng = -1 ok = 10**12+100 while ok - ng > 1: mid = (ok + ng) // 2 c = 0 for a,f in zip(A,F): c += max(0,a-mid//f) if c <= K: ok = mid else: ng = mid print(ok)
p02883
N,K = list(map(int,input().split())) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) ng = -1 ok = 10**12+100 while ok - ng > 1: mid = (ok + ng) // 2 if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K: ok = mid else: ng = mid print(ok)
import sys readline = sys.stdin.readline N,K = list(map(int,readline().split())) A = list(map(int,readline().split())) F = list(map(int,readline().split())) A.sort() F.sort(reverse=True) ng = -1 ok = 10**12+100 while ok - ng > 1: mid = (ok + ng) // 2 if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K: ok = mid else: ng = mid print(ok)
p02883
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n, k = list(map(int, readline().split())) a = list(map(int, readline().split())) a.sort() f = list(map(int, readline().split())) f.sort(reverse=True) cor_v = 10 ** 22 inc_v = -1 while cor_v - inc_v > 1: bin_v = (cor_v + inc_v) // 2 cost = 0 #条件を満たすcostを全検索 for i in range(n): if a[i] * f[i] >= bin_v: cost += ((a[i] * f[i]) - bin_v + f[i] - 1) // f[i] if cost > k: break #costが制約を満たすか if cost <= k: cor_v = bin_v else: inc_v = bin_v print(cor_v) if __name__ == '__main__': solve()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n, k = list(map(int, readline().split())) a = list(map(int, readline().split())) a.sort() f = list(map(int, readline().split())) f.sort(reverse=True) cor_v = 10 ** 13 inc_v = -1 while cor_v - inc_v > 1: bin_v = (cor_v + inc_v) // 2 cost = 0 #条件を満たすcostを全検索 for i in range(n): if a[i] * f[i] >= bin_v: cost += ((a[i] * f[i]) - bin_v + f[i] - 1) // f[i] if cost > k: break #costが制約を満たすか if cost <= k: cor_v = bin_v else: inc_v = bin_v print(cor_v) if __name__ == '__main__': solve()
p02883
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n, k = list(map(int, input().rstrip('\n').split())) a = list(map(int, input().rstrip('\n').split())) a.sort() f = list(map(int, input().rstrip('\n').split())) f.sort(reverse=True) cor_v = 10 ** 20 inc_v = -1 while cor_v - inc_v > 1: bin_v = (cor_v + inc_v) // 2 cost = 0 #条件を満たすcostを全検索 for i in range(n): t = a[i] * f[i] if t > bin_v: cost += (t - bin_v + f[i] - 1) // f[i] #costが制約を満たすか if cost <= k: cor_v = bin_v else: inc_v = bin_v print(cor_v) if __name__ == '__main__': solve()
import sys def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n, k = list(map(int, input().rstrip('\n').split())) a = list(map(int, input().rstrip('\n').split())) a.sort() f = list(map(int, input().rstrip('\n').split())) f.sort(reverse=True) cor_v = 10 ** 13 inc_v = -1 while cor_v - inc_v > 1: bin_v = (cor_v + inc_v) // 2 cost = 0 #条件を満たすcostを全検索 for i in range(n): t = a[i] * f[i] if t > bin_v: cost += (t - bin_v + f[i] - 1) // f[i] #costが制約を満たすか if cost <= k: cor_v = bin_v else: inc_v = bin_v print(cor_v) if __name__ == '__main__': solve()
p02883
n,k=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) a=sorted(a,reverse=True) b=sorted(b) def ok(N): sums=0 for i in range(n): sums+=max(0,a[i]-N//b[i]) if sums<=k: return True else: return False import math left=0 right=a[0]*b[-1] P=0 for i in range(41): if 2**i<=right<2**(i+1): P=i+1 break for _ in range(P): if ok(math.floor((left+right)/2)): left=left right=(left+right)/2 elif not ok(math.floor((left+right)/2)): left=(left+right)/2 right=right print((math.floor(right)))
# いきぬきreview 忘れた問題 # gluttony N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) F.sort() A.sort(reverse=True) def func(X): s = 0 for i in range(N): a, f = A[i], F[i] s += max(0, a-X//f) return s <= K R = 10**12 L = -1 while R-L > 1: m = (R+L)//2 if func(m): R = m else: L = m print(R)
p02883
from math import ceil N,K=list(map(int, input().split())) A=list(map(int, input().split())) F=list(map(int, input().split())) A=sorted(A) F=sorted(F, reverse=True) left=0 right=10**12+1 ans=float("INF") while True: mid=(left+right)//2 now=0 for i in range(N): if F[i]*A[i]>mid: now+=ceil(((F[i]*A[i])-mid)/F[i]) #print(now, mid) if now==K: ans=min(ans, mid) right=mid elif now>K: if left==mid: break left=mid else: if right==mid: break right=mid ans=min(ans, mid) print(ans)
from math import ceil N,K=list(map(int, input().split())) A=list(map(int, input().split())) F=list(map(int, input().split())) A=sorted(A) F=sorted(F, reverse=True) left=0 right=10**12+1 ans=float("INF") while True: mid=(left+right)//2 now=0 for i in range(N): if F[i]*A[i]>mid: now+=ceil(((F[i]*A[i])-mid)/F[i]) #print(now, mid) if now==K: ans=min(ans, mid) if right==mid: break right=mid elif now>K: if left==mid: break left=mid else: if right==mid: break right=mid ans=min(ans, mid) print(ans)
p02883
N,K = list(map(int,input().split())) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse = True) M = 0 for i in range(N): M=max(F[i]*A[i],M) def judge(n): score = 0 for i in range(N): score += max(A[i] - n//F[i],0) return score<=K def bisect(l,r): while r-l>1: if judge((l+r)//2): r = (l+r)//2 else: l = (l+r)//2 return r if judge(0): print((0)) else: print((bisect(0,M)))
N,K = list(map(int,input().split())) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) def check(v): ans = 0 for i in range(N): ans += max(A[i] - v//F[i],0) return ans<=K if check(0): print((0)) else: l = 0 r = 10**12 + 1 while r-l>1: if check((l+r)//2): r = (l+r)//2 else: l = (l+r)//2 print(r)
p02883
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) r = A[-1]*F[0] l = -1 while(r-l > 1): tmp = (l+r)//2 k = 0 for x, y in zip(A, F): if x*y > tmp: k += x - (tmp // y) #k += max(0, x - (tmp // y)) if K >= k: r = tmp else: l = tmp print(r)
def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) r = A[-1]*F[0] l = -1 while(r-l > 1): tmp = (l+r)//2 k = 0 for x, y in zip(A, F): if x*y > tmp: k += x - (tmp // y) #k += max(0, x - (tmp // y)) if K >= k: r = tmp else: l = tmp print(r) main()
p02883
n, k = list(map(int, input().split())) a = list(map(int, input().split())) f = list(map(int, input().split())) a = sorted(a) f = sorted(f)[::-1] def c(x): # x決めると必要な修行回数も決まる res = 0 for O, K in zip(a, f): d = max(0, O * K - x) res += (d + K - 1) // K return res <= k l = -1 r = 1 << 60 while r - l > 1: mid = (l + r) >> 1 if c(mid): r = mid else: l = mid print(r)
n, k = list(map(int, input().split())) a = sorted(map(int, input().split())) f = sorted(map(int, input().split()))[::-1] # 成績 Σ{i=1~n}a[i]*f[i] # a[i]小さいの、f[i]でかいの組み合わせるとよい(交換しても悪化しない) def c(x): need = 0 for i in range(n): if a[i] * f[i] > x: # f[i]を何回減らしてx以下にできるか diff = a[i] * f[i] - x need += 0 - - diff // f[i] return need <= k l = 0 r = 1 << 60 while r != l: mid = (l + r) >> 1 if c(mid): r = mid else: l = mid + 1 print(l)
p02883
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A = sorted(A) F = sorted(F, reverse=True) l = -1 # 絶対にfalse r = 10**12+5 while (l+1<r): c = (l+r)//2 s = 0 for i in range(N): s += max(0, A[i]-(c//F[i])) if s <= K: r = c else: l = c print(r)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A = sorted(A) F = sorted(F, reverse=True) l = -1 r = 10**12+5 while (l+1<r): c = (l+r)//2 tmp = 0 for i in range(N): tmp += max(0, A[i]-(c//F[i])) if tmp <= K: r = c else: l = c print(r)
p02883
n,k = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) def isOk(x): cost = 0 for a, f in zip(A,F): eatable = x//f if eatable >= a: continue cost += a - eatable if cost <= k: return True return False left = -1 right = A[-1] * F[0] while left+1 < right: mid = int(left + (right-left)//2) if isOk(mid): right = mid else: left = mid print(right)
n,k = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) def isOk(x): cost = 0 for a, f in zip(A,F): eatable = x//f if eatable >= a: continue cost += a - eatable if cost <= k: return True return False left = -1 right = A[-1] * F[0] while left+1 < right: # mid = int(left + (right-left)//2) mid = (left+right)//2 if isOk(mid): right = mid else: left = mid print(right)
p02883
N, K = list(map(int,input().split())) A = list(map(int,input().split())) F = list(map(int,input().split())) A = sorted(A) F = sorted(F, reverse=True) mul = [A[i]*F[i] for i in range(N)] if K >= sum(A)*N: print((0)) exit() ma = 2**40 mi = 0 while 1: tgt = mi + (ma - mi)//2 num = 0 for i in range(N): tmp = (mul[i] - tgt + F[i] - 1) // F[i] if tmp < 0: tmp = 0 num += tmp if ma == mi: print(ma) exit() if num <= K: ma = mi + (ma - mi)//2 else: mi = mi + (ma - mi)//2+1
N, K = list(map(int,input().split())) A = list(map(int,input().split())) F = list(map(int,input().split())) A = sorted(A) F = sorted(F, reverse=True) mul = [A[i]*F[i] for i in range(N)] if K >= sum(A): print((0)) exit() ma = 2**40 mi = 0 while 1: tgt = mi + (ma - mi)//2 num = 0 for i in range(N): tmp = (mul[i] - tgt + F[i] - 1) // F[i] if tmp <= 0: continue num += tmp if ma == mi: print(ma) exit() if num <= K: ma = mi + (ma - mi)//2 else: mi = mi + (ma - mi)//2+1
p02883
import sys from io import StringIO import unittest import math def check(A, F, x, N, K): for i in range(N): if A[i] * F[i] > x: k = math.ceil(A[i] - x / F[i]) K -= k if K < 0: return False else: return True def resolve(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort(reverse=True) F.sort() # binary search l = 0 r = max(A) * max(F) result = None while l <= r: # print('l {}, r {}'.format(l, r)) if l == r: result = l break mid = (l + r) // 2 if check(A, F, mid, N, K): r = mid else: l = mid + 1 print(result) class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """3 5 4 2 1 2 3 1""" output = """2""" self.assertIO(input, output) def test_入力例_2(self): input = """3 8 4 2 1 2 3 1""" output = """0""" self.assertIO(input, output) def test_入力例_3(self): input = """11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2""" output = """12""" self.assertIO(input, output) if __name__ == "__main__": # unittest.main() resolve()
import math def check(A, F, x, N, K): for i in range(N): if A[i] * F[i] > x: k = math.ceil(A[i] - x / F[i]) K -= k if K < 0: return False else: return True def resolve(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort(reverse=True) F.sort() # binary search l = 0 r = max(A) * max(F) result = None while l <= r: # print('l {}, r {}'.format(l, r)) if l == r: result = l break mid = (l + r) // 2 if check(A, F, mid, N, K): r = mid else: l = mid + 1 print(result) if __name__ == "__main__": resolve()
p02883
import heapq n, k = list(map(int, input().split())) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort(reverse=True) f.sort() pq = [] for i in range(n): heapq.heappush(pq, (-a[i]*f[i], a[i], f[i])) for i in range(k): score, ai, fi = heapq.heappop(pq) if score == 0: heapq.heappush(pq, (0, 0, 0)) break heapq.heappush(pq, (-((ai-1) * fi), ai-1, fi)) print((-heapq.heappop(pq)[0]))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort(reverse=True) f.sort() ori = [0] * n for i in range(n): ori[i] = a[i]*f[i] ok = max(ori) ng = -1 mid = (ok+ng) // 2 while ok - ng > 1: cnt = 0 flg = 0 for i in range(n): if ori[i] > mid: cnt += (a[i] - mid // f[i]) if cnt > k: flg = 1 break if flg: ng = mid else: ok = mid mid = (ok + ng) // 2 print(ok)
p02883
import sys import heapq sys.setrecursionlimit(10**7) INTMAX = 9223372036854775807 INTMIN = -9223372036854775808 DVSR = 1000000007 def POW(x, y): return pow(x, y, DVSR) def INV(x, m=DVSR): return pow(x, m - 2, m) def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m def LI(): return [int(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def II(): return int(eval(input())) def FLIST(n): res = [1] for i in range(1, n+1): res.append(res[i-1]*i%DVSR) return res N,K=LI() As=LI() As.sort() Fs=LI() Fs.sort(reverse=True) HQ=[] for i in range(N): heapq.heappush(HQ, (-As[i]*Fs[i], As[i], Fs[i])) # print(HQ) while K: score,A,F=heapq.heappop(HQ) if HQ: score2,A2,F2=HQ[0] diff = min((score2 - score) // F + 1, K) heapq.heappush(HQ, (-(A-diff)*F , A-diff, F)) K = K - diff else: print((max(A-K,0)*F)) exit() ans, _, _ =heapq.heappop(HQ) print((-ans))
import sys import heapq sys.setrecursionlimit(10**7) INTMAX = 9223372036854775807 INTMIN = -9223372036854775808 DVSR = 1000000007 def POW(x, y): return pow(x, y, DVSR) def INV(x, m=DVSR): return pow(x, m - 2, m) def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m def LI(): return [int(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().split() def II(): return int(eval(input())) def FLIST(n): res = [1] for i in range(1, n+1): res.append(res[i-1]*i%DVSR) return res N,K=LI() As=LI() As.sort() Fs=LI() Fs.sort(reverse=True) rgt = 10**12 lft = 0 while lft < rgt: cost = K half = (lft + rgt) // 2 for i in range(N): if As[i]*Fs[i] > half: cost -= (As[i]*Fs[i] - half) // Fs[i] cost -= 1 if (half - As[i]*Fs[i]) % Fs[i] > 0 else 0 if cost < 0: lft = half + 1 else: rgt = half # print(lft, rgt) print(rgt)
p02883
N, K = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) F = sorted(list(map(int, input().split())), reverse=True) def isEaten(x): temp = 0 for i in range(N): t = x // F[i] if t < A[i]: temp += (A[i] - t) if temp > K: return False else: return True def bitSearch(r, l): m = (r+l) // 2 if m == l: if isEaten(l): print(l) else: print(r) exit() elif isEaten(m): bitSearch(m, l) else: bitSearch(r, m) target = max([A[i]*F[i] for i in range(N)]) bitSearch(target, 0)
N, K = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) F = sorted(list(map(int, input().split())), reverse=True) def isEaten(x): temp = 0 for i in range(N): t = x // F[i] if t < A[i]: temp += (A[i] - t) return temp <= K def bitSearch(r, l): m = (r+l) // 2 if m == l: if isEaten(l): print(l) else: print(r) exit() elif isEaten(m): bitSearch(m, l) else: bitSearch(r, m) target = max([A[i]*F[i] for i in range(N)]) bitSearch(target, 0)
p02883
import sys import heapq def main(): n, k = [int(s) for s in sys.stdin.readline().strip().split()] a = [int(s) for s in sys.stdin.readline().strip().split()] f = [int(s) for s in sys.stdin.readline().strip().split()] # n, k = 3, 5 # a = [4, 2,1] # f = [2, 3, 1] a.sort(reverse=True) f.sort() heap = [] for i in range(n): ai = a[i] fi = f[i] heap.append((- ai * fi, ai, fi)) heapq.heapify(heap) for i in range(k): prod, ai, fi = heapq.heappop(heap) if prod == 0: break new_prod = - (ai - 1) * fi heapq.heappush(heap, (new_prod, ai-1, fi)) print((- heap[0][0])) main()
import sys import heapq def main(): n, k = [int(s) for s in sys.stdin.readline().strip().split()] a = [int(s) for s in sys.stdin.readline().strip().split()] f = [int(s) for s in sys.stdin.readline().strip().split()] # n, k = 3, 5 # a = [4, 2,1] # f = [2, 3, 1] a.sort(reverse=True) f.sort() def possible(x1): improved = 0 for i in range(n): before = a[i] * f[i] if before > x1: needed_to_be_reduced = before - x1 if needed_to_be_reduced % f[i] == 0: plus_one = 0 else: plus_one = 1 improved += (needed_to_be_reduced // f[i]) + plus_one if improved > k: return False return True def b_search(): lo = 0 hi = 10 ** 12 # (lo, hi] # hi is always possible # lo might be possible while lo < hi: mid = (lo + hi) // 2 if possible(mid): hi = mid else: lo = mid+1 return hi ans = b_search() print(ans) main()
p02883
import math N, K = list(map(int, input().split())) As = sorted(list(map(int, input().split()))) Bs = sorted(list(map(int, input().split())))[::-1] Cs = [a*b for a, b in zip(As, Bs)] BCs = list(zip(Bs, Cs)) def func(target): r = 0 for b, c in BCs: r += math.ceil(max(0, c - target) / b) return r <= K if __name__ == '__main__': min_i, max_i, index = -1, max(Cs)+1, 1 while True: if func(index): index, max_i = (index-1 + min_i)//2, index-1 continue index, min_i = (index+1 + max_i)//2, index+1 if min_i > max_i: print(min_i) break
import math N, K = list(map(int, input().split())) As = sorted(list(map(int, input().split()))) Bs = sorted(list(map(int, input().split())))[::-1] Cs = [a*b for a, b in zip(As, Bs)] BCs = list(zip(Bs, Cs)) def func(target): r = 0 for b, c in BCs: r += math.ceil(max(0, c - target) / b) return r <= K if __name__ == '__main__': min_i, max_i, index = 0, max(Cs)+1, 1 while True: if func(index): index, max_i = (index-1 + min_i)//2, index-1 else: index, min_i = (index+1 + max_i)//2, index+1 if min_i > max_i: print(min_i) break
p02883
import math N,K=list(map(int,input().split())) X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])] m,M,i=0,10**12,1 exec("i,M,m=((i+m)//2,i,m) if sum(math.ceil(max(0,c-i)/b)for b, c in X)<=K else((i+M)//2,M,i);"*50) print(M)
N,K=list(map(int,input().split())) X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[::-1])] m,M,i=0,2**40,1 exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-c)//b for b, c in X)<=K else((i+M)//2,M,i);"*50) print(M)
p02883
(_,K),*T=[list(map(int,t.split()))for t in open(0)] A,B=list(map(sorted,T)) m,M,i=0,2**40,1 exec("i,M,m=((i+m)//2,i,m) if -sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K else((i+M)//2,M,i);"*41) print(M)
(_,K),*T=[list(map(int,t.split()))for t in open(0)] A,B=list(map(sorted,T)) d=[0,2**40] exec("i=sum(d)//2;d[-sum(min(0,i-a*b)//b for a,b in zip(A,B[::-1]))<=K]=i;"*41) print((d[1]))
p02883
import heapq as hq N, K = list(map(int, input().split())) A = list(map(int,input().split())) A.sort() F = list(map(int,input().split())) F.sort() q = [(-A[i]*F[N-1-i], F[N-1-i]) for i in range(N)] hq.heapify(q) cnt = 0 while cnt < K: cnt += 1 c = hq.heappop(q) if c[0] < 0: hq.heappush(q, (c[0]+c[1], c[1])) else: hq.heappush(q, c) break print((-hq.heappop(q)[0]))
import heapq as hq N, K = list(map(int, input().split())) A = list(map(int,input().split())) A.sort() F = list(map(int,input().split())) F.sort() if sum(A) <= K: print((0)) exit() ans = max([A[i]*F[N-1-i] for i in range(N)]) def achievable(score): cnt = 0 for i in range(N): a,f = A[i], F[N-1-i] if a*f > score: n = score // f cnt += a-n if cnt > K: return False return True l,r = 0, ans while r - l > 1: p = (l + r) // 2 if achievable(p): r = p else: l = p print(r)
p02883
#!/usr/bin/env python3 import sys INF = float("inf") import math import heapq import copy def solve(N: int, K: int, A: "List[int]", F: "List[int]"): h = [] A.sort() F.sort(reverse=True) for a, f in zip(A, F): heapq.heappush(h, (-a*f, a, f)) maxtime = heapq.nsmallest(1, h) maxtime = -maxtime[0][0] def isOK(y): hh = copy.copy(h) counter = 0 while len(hh) > 0: p, a, f = heapq.heappop(hh) if -p > y: counter += a-y//f if counter > K: return False else: break return counter <= K def binary_search(x): ng = -1 ok = len(x) while abs(ok - ng) > 1: mid = (ok + ng)//2 # print("mid: {}, in ({}, {})".format(mid, ng, ok)) if isOK(mid): ok = mid else: ng = mid return ng, ok ng, ok = binary_search(list(range(maxtime))) print(ok) # while k > 0: # p1, a1, f1 = heapq.heappop(h) # p2, a2, f2 = heapq.heappop(h) # p1, p2 = -p1, -p2 # sub = min(a1 - math.ceil((p2/f1)-1), k) # a1 -= sub # k -= sub # heapq.heappush(h, (-a1*f1, a1, f1)) # heapq.heappush(h, (-a2*f2, a2, f2)) # # print(h) # p, a, f = heapq.heappop(h) # print(-p) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" F = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, K, A, F) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys INF = float("inf") from bisect import bisect_left def solve(N: int, K: int, A: "List[int]", F: "List[int]"): A.sort() F.sort(reverse=True) h = [] for a, f in zip(A, F): h.append((a*f, a, f)) h.sort() maxtime = h[-1][0] def isOK(y): i = bisect_left(h, (y+1, -1, -1)) counter = 0 # print(h[i:]) for p, a, f in h[i:]: counter += a-y//f return counter <= K def binary_search(x): ng = -1 ok = len(x) while abs(ok - ng) > 1: mid = (ok + ng)//2 # print("mid: {}, in ({}, {})".format(mid, ng, ok)) if isOK(mid): ok = mid else: ng = mid return ng, ok ng, ok = binary_search(list(range(maxtime))) print(ok) # while k > 0: # p1, a1, f1 = heapq.heappop(h) # p2, a2, f2 = heapq.heappop(h) # p1, p2 = -p1, -p2 # sub = min(a1 - math.ceil((p2/f1)-1), k) # a1 -= sub # k -= sub # heapq.heappush(h, (-a1*f1, a1, f1)) # heapq.heappush(h, (-a2*f2, a2, f2)) # # print(h) # p, a, f = heapq.heappop(h) # print(-p) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" F = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, K, A, F) if __name__ == '__main__': main()
p02883
import sys input = sys.stdin.readline import math def solve(): n,k = (int(i) for i in input().split()) a = sorted(list(int(i) for i in input().split())) f = sorted(list(int(i) for i in input().split()),reverse = True) if sum(a) <= k: print((0)) exit() ng = 0 ok = 10**15 while ok-ng >1 : next = (ok+ng)//2 #a*fの値がnext以下になるか判定する tmpk = k for i in range(n): ta = a[i] tf = f[i] if ta*tf > next: tmpk -= math.ceil((ta*tf-next)/tf) if tmpk < 0: ng = next else: ok = next print(ok) solve()
import sys input = sys.stdin.readline import math def solve(): n,k = (int(i) for i in input().split()) a = sorted(list(int(i) for i in input().split())) f = sorted(list(int(i) for i in input().split()),reverse = True) if sum(a) <= k: print((0)) exit() ng = 0 ok = 10**12 while ok-ng >1 : next = (ok+ng)//2 #a*fの値がnext以下になるか判定する tmpk = k for i in range(n): ta = a[i] tf = f[i] if ta*tf > next: tmpk -= math.ceil((ta*tf-next)/tf) if tmpk < 0: ng = next else: ok = next print(ok) solve()
p02883
def ints(): return [int(x) for x in input().split()] def ii(): return int(eval(input())) import math N, K = ints() A = list(sorted(ints())) F = list(reversed(sorted(ints()))) AF = [A[i]*F[i] for i in range(N)] afmax = max(AF) def can(max_af): k = K for i in range(N): af = AF[i] if af>max_af: max_ai = max_af // F[i] k -= A[i]-max_ai if k<0: return False return k>=0 l = -1 r = afmax while r-l>1: m = (l+r)//2 if can(m): r = m else: l = m print(r)
def ints(): return [int(x) for x in input().split()] def ii(): return int(eval(input())) import math N, K = ints() A = list(sorted(ints())) F = list(reversed(sorted(ints()))) AF = [A[i]*F[i] for i in range(N)] afmax = max(AF) def can(seiseki): k = K for i in range(N): af = AF[i] if af>seiseki: k -= math.ceil((af-seiseki)/F[i]) if k<0: return False return k>=0 l = -1 r = afmax while r-l>1: m = (l+r)//2 if can(m): r = m else: l = m print(r)
p02883
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K, *AF = list(map(int, read().split())) A = AF[:N] F = AF[N:] A.sort() F.sort(reverse=True) C = [a * f for a, f in zip(A, F)] def is_ok(cost): k = 0 for c, f in zip(C, F): if c > cost: k += (c - cost + f - 1) // f return k <= K ok = max(C) ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid print(ok) return if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K, *AF = list(map(int, read().split())) A = AF[:N] F = AF[N:] A.sort() F.sort(reverse=True) C = [a * f for a, f in zip(A, F)] def is_ok(cost): k = 0 for i in range(N): if C[i] > cost: k += (C[i] - cost + F[i] - 1) // F[i] return k <= K ok = max(C) ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid print(ok) return if __name__ == '__main__': main()
p02883
n,k=list(map(int,input().split())) A=[int(i) for i in input().split()] F=[int(i) for i in input().split()] A.sort() F.sort() def chk(x): ct=0 for i in range(n): a,f=A[i],F[-i-1] ct+=max(0,a-x//f) if ct<=k: return True else: return False l,r=0,A[-1]*F[-1] while r-l>1: m=(l+r)//2 if chk(m): r=m else: l=m if chk(l): print(l) else: print(r)
n,k=list(map(int,input().split())) A=[int(i) for i in input().split()] F=[int(i) for i in input().split()] A.sort() F.sort() def chk(x): ct=0 for i in range(n): a,f=A[i],F[-i-1] ct+=max(0,a-x//f) if ct>k: return False if ct<=k: return True else: return False l=0 r=0 for i in range(n): r=max(r,A[i]*F[-i-1]) while r-l>1: m=(l+r)//2 if chk(m): r=m else: l=m if chk(l): print(l) else: print(r)
p02883
n,k=list(map(int,input().split())) A=[int(i) for i in input().split()] F=[int(i) for i in input().split()] A.sort() F.sort() def chk(x): ct=0 for i in range(n): a,f=A[i],F[-i-1] ct+=max(0,a-x//f) if ct>k: return False if ct<=k: return True else: return False l=0 r=0 for i in range(n): r=max(r,A[i]*F[-i-1]) while r-l>1: m=(l+r)//2 if chk(m): r=m else: l=m if chk(l): print(l) else: print(r)
n,k=list(map(int,input().split())) A=[int(i) for i in input().split()] F=[int(i) for i in input().split()] A.sort() F.sort() def chk(x): ct=0 for i in range(n): a,f=A[i],F[-i-1] ct+=max(0,a-x//f) if ct<=k: return True else: return False l,r=0,A[-1]*F[-1] while r-l>1: m=(l+r)//2 if chk(m): r=m else: l=m if chk(l): print(l) else: print(r)
p02883
import bisect import math (n,k),a,f = [list(map(int, s.split())) for s in open(0)] a.sort() f.sort(reverse=True) for ans in range(a[-1] * f[-1] + 1): tmp = 0 for x, y in zip(a,f): tmp += x - math.floor(ans / y) if tmp <= k: break print(ans)
import math (n,k),a,f = [list(map(int, s.split())) for s in open(0)] a.sort() f.sort(reverse=True) low = 0 high = 0 for x, y in zip(a,f): high = max(high, x*y) while high != low: test = int((high + low) // 2) tmp = 0 for x, y in zip(a,f): tmp += max(0, x - math.floor(test / y)) if tmp > k: low = test + 1 break else: high = test print(high)
p02883
import math (n,k),a,f = [list(map(int, s.split())) for s in open(0)] a.sort() f.sort(reverse=True) low = 0 high = 0 for x, y in zip(a,f): high = max(high, x*y) while high != low: test = int((high + low) // 2) tmp = 0 for x, y in zip(a,f): tmp += max(0, x - math.floor(test / y)) if tmp > k: low = test + 1 break else: high = test print(high)
(n,k),a,f = [list(map(int, s.split())) for s in open(0)] a.sort(reverse=True) f.sort() low = 0 high = 0 for x, y in zip(a,f): high = max(high, x*y) while high != low: test = int((high + low) // 2) tmp = 0 for x, y in zip(a,f): tmp += max(0, x - int(test / y)) if tmp > k: low = test + 1 break else: high = test print(high)
p02883
import bisect n, k = list(map(int, input().split())) a = list(map(int, input().split())) f = list(map(int, input().split())) a = sorted(a) f = sorted(f, reverse=True) score = sorted(((x * y, x, y) for (x, y) in zip(a, f))) for _ in range(k): p, x, y = score.pop() if x > 0: x -= 1 bisect.insort(score, (x * y, x, y)) p, _, _ = score.pop() print(p)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) f = list(map(int, input().split())) a = sorted(a) f = sorted(f, reverse=True) def judge(n): s = 0 for x, y in zip(a, f): s += max(0, x - n // y) if s <= k: return True else: return False low = 0 high = a[-1] * f[0] while high - low > 0: mid = (high + low) // 2 if judge(mid): high = mid else: low = mid + 1 print(high)
p02883
import math n,k=list(map(int,input().split())) a=sorted([int(i) for i in input().split()],reverse=True) f=sorted([int(i) for i in input().split()]) c=[[a[i],f[i]] for i in range(n)] c.sort(key=lambda x:x[0]*x[1],reverse=True) if n==1: print((max(0,(c[0][0]-k)*c[0][1]))) else: while True: #print(c) if k==0 or c[0][0]==0: break elif c[0][0]*c[0][1]-c[1][0]*c[1][1]==0: k-=1 c[0][0]-=1 elif c[0][0]*c[0][1]-c[1][0]*c[1][1] < c[0][1]: k-=1 c[0][0]-=1 else: l=math.ceil((c[0][0]*c[0][1]-c[1][0]*c[1][1])/c[0][1]) m=min(l,c[0][0]) k-=m c[0][0]-=m for i in range(n-1): if c[i][0]*c[i][1]<=c[i+1][0]*c[i+1][1]: c[i],c[i+1]=c[i+1],c[i] else: break #print(c) print((c[0][0]*c[0][1]))
n,k=list(map(int,input().split())) a=sorted(list(map(int,input().split()))) #こっちは変えられない f=sorted(list(map(int,input().split())),reverse=True) l,r=0,10**12 def cal(x): global n,f,a,k ret=0 for i in range(n): ret+=max(0,a[i]-(x//f[i])) #print(ret,x) return ret while l+1<r: x=l+(r-l)//2 if cal(x)<=k: r=x else: l=x if cal(l)<=k: print(l) else: print(r)
p02883
import bisect import sys sys.setrecursionlimit(10**9) INF = 10**20 def main(): N,K = list(map(int,input().split())) A=list(map(int,input().split())) F=list(map(int,input().split())) A.sort() F.sort(reverse=True) B=[] for i in range(N): B.append((A[i]*F[i],F[i])) B.sort() for _ in range(K): if not len(B) > 0: break b,f = B.pop() front = (b-f,f) if b-f > 0: bisect.insort(B,front) print((max(B)[0] if len(B) > 0 else 0)) # print(B) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**9) INF = 10**20 def main(): N,K = list(map(int,input().split())) A=list(map(int,input().split())) F=list(map(int,input().split())) A.sort() F.sort(reverse=True) def c(s): # sに対して単調減少 sum_x = 0 for i in range(N): a,f=A[i],F[i] tp = s//f if not a <= tp: sum_x += a-tp return sum_x <= K l=-1 r=10**20 while r-l>1: mid = (l+r)//2 if c(mid): r = mid else: l = mid print(r) if __name__ == "__main__": main()
p02883
def floor_sum(n, m, a, b): res = 0 while True: res += (n - 1) * n * (a // m) // 2 a %= m res += n * (b // m) b %= m y_max = (a * n + b) // m if y_max == 0: break x_max = y_max * m - b res += (n - (x_max + a - 1) // a) * y_max n, m, a, b = y_max, a, m, -x_max % a return res import sys input = sys.stdin.buffer.readline T = int(eval(input())) res = [None] * T for i in range(T): n, m, a, b = list(map(int, input().split())) res[i] = str(floor_sum(n, m, a, b)) print(('\n'.join(res)))
def floor_sum(n, m, a, b): res = 0 while True: if a >= m: res += (n - 1) * n * (a // m) // 2 a %= m if b >= m: res += n * (b // m) b %= m y_max = (a * n + b) // m if y_max == 0: break x_max = b - y_max * m res += (n + x_max // a) * y_max n, m, a, b = y_max, a, m, x_max % a return res import sys input = sys.stdin.buffer.readline T = int(eval(input())) res = [None] * T for i in range(T): n, m, a, b = list(map(int, input().split())) res[i] = str(floor_sum(n, m, a, b)) print(('\n'.join(res)))
p02560
def floor_sum(n, m, a, b): res = 0 while True: if a >= m: res += (n - 1) * n * (a // m) // 2 a %= m if b >= m: res += n * (b // m) b %= m y_max = (a * n + b) // m if y_max == 0: break x_max = b - y_max * m res += (n + x_max // a) * y_max n, m, a, b = y_max, a, m, x_max % a return res import sys input = sys.stdin.buffer.readline T = int(eval(input())) res = [None] * T for i in range(T): n, m, a, b = list(map(int, input().split())) res[i] = str(floor_sum(n, m, a, b)) print(('\n'.join(res)))
def floor_sum(n, m, a, b): res = 0 while True: if a >= m: res += (n - 1) * n * (a // m) // 2 a %= m if b >= m: res += n * (b // m) b %= m y_max = (a * n + b) // m if y_max == 0: break x_max = b - y_max * m res += (n + x_max // a) * y_max n, m, a, b = y_max, a, m, x_max % a return res import sys input = sys.stdin.buffer.readline T = int(eval(input())) res = [''] * T for i in range(T): n, m, a, b = list(map(int, input().split())) res[i] = str(floor_sum(n, m, a, b)) print(('\n'.join(res)))
p02560
import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def floor_sum(n,m,a,b): # sum((A*i+B)//M for i in range(N)) res = 0 res += (a//m)*n*(n-1)//2 + (b//m)*n a %= m b %= m y_max = (a*n+b)//m if y_max == 0: return res x_max = m*y_max-b res += (n+(-x_max)//a)*y_max res += floor_sum(y_max,a,m,(x_max+a-1)//a*a-x_max) return res T = I() for i in range(T): n,m,a,b = MI() print((floor_sum(n,m,a,b)))
import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def floor_sum(n,m,a,b): # sum((A*i+B)//M for i in range(N)) res = 0 if a >= m: res += (a//m)*n*(n-1)//2 a %= m if b >= m: res += (b//m)*n b %= m y_max = (a*n+b)//m if y_max == 0: return res x_max = m*y_max-b res += (n+(-x_max)//a)*y_max res += floor_sum(y_max,a,m,(x_max+a-1)//a*a-x_max) return res T = I() for i in range(T): n,m,a,b = MI() print((floor_sum(n,m,a,b)))
p02560
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 10 ** 9 + 7 def floor_sum_1(n, m, a, b): ret = 0 if a >= m: ret += (n - 1) * n * (a // m) // 2 a %= m if b >= m: ret += n * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: return ret ret += (n - (x_max + a - 1) // a) * y_max ret += floor_sum(y_max, a, m, (a - x_max % a) % a) return ret def floor_sum(n, m, a, b): ret = 0 while True: if a >= m: ret += (n - 1) * n * (a // m) // 2 a %= m if b >= m: ret += n * (b // m) b %= m if a * n + b < m: return ret y_max = (a * n + b) // m x_max = y_max * m - b ret += (n - (x_max + a - 1) // a) * y_max n = y_max m, a, b = a, m, (a - x_max % a) % a def debug(*x): print(*x, file=sys.stderr) def solve(SOLVE_PARAMS): pass def main(): # parse input T = int(input()) for _t in range(T): N, M, A, B = map(int, input().split()) print(floor_sum(N, M, A, B)) # tests T1 = """ 5 4 10 6 3 6 5 4 3 1 1 0 0 31415 92653 58979 32384 1000000000 1000000000 999999999 999999999 """ TEST_T1 = """ >>> as_input(T1) >>> main() 3 13 0 314095480 499999999500000000 """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 10 ** 9 + 7 def floor_sum_1(n, m, a, b): ret = 0 if a >= m: ret += (n - 1) * n * (a // m) // 2 a %= m if b >= m: ret += n * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: return ret ret += (n - (x_max + a - 1) // a) * y_max ret += floor_sum(y_max, a, m, (a - x_max % a) % a) return ret def floor_sum(n, m, a, b): ret = 0 while True: if a >= m: # ret += (n - 1) * n * (a // m) // 2 ret += (a // m) * (n - 1) * n // 2 a %= m if b >= m: ret += n * (b // m) b %= m if a * n + b < m: return ret y_max = (a * n + b) // m x_max = y_max * m - b ret += (n - (x_max + a - 1) // a) * y_max n = y_max m, a, b = a, m, (a - x_max % a) % a def debug(*x): print(*x, file=sys.stderr) def solve(SOLVE_PARAMS): pass def main(): # parse input T = int(input()) for _t in range(T): N, M, A, B = map(int, input().split()) print(floor_sum(N, M, A, B)) # tests T1 = """ 5 4 10 6 3 6 5 4 3 1 1 0 0 31415 92653 58979 32384 1000000000 1000000000 999999999 999999999 """ TEST_T1 = """ >>> as_input(T1) >>> main() 3 13 0 314095480 499999999500000000 """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
p02560
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**6) INF = 10 ** 9 + 1 # sys.maxsize # float("inf") MOD = 10 ** 9 + 7 def floor_sum_1(n, m, a, b): ret = 0 if a >= m: ret += (n - 1) * n * (a // m) // 2 a %= m if b >= m: ret += n * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: return ret ret += (n - (x_max + a - 1) // a) * y_max ret += floor_sum(y_max, a, m, (a - x_max % a) % a) return ret def floor_sum(n, m, a, b): ret = 0 while True: if a >= m: ret += (a // m) * (n - 1) * n // 2 a %= m if b >= m: ret += n * (b // m) b %= m if a * n + b < m: return ret y_max = (a * n + b) // m x_max = y_max * m - b ret += (n - (x_max + a - 1) // a) * y_max n = y_max m, a, b = a, m, -x_max % a def debug(*x): print(*x, file=sys.stderr) def solve(SOLVE_PARAMS): pass def main(): # parse input T = int(input()) for _t in range(T): N, M, A, B = map(int, input().split()) print(floor_sum(N, M, A, B)) # tests T1 = """ 5 4 10 6 3 6 5 4 3 1 1 0 0 31415 92653 58979 32384 1000000000 1000000000 999999999 999999999 """ TEST_T1 = """ >>> as_input(T1) >>> main() 3 13 0 314095480 499999999500000000 """ def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
#!/usr/bin/env python3 import sys def floor_sum(n, m, a, b): ret = 0 while True: if a >= m: ret += (a // m) * (n - 1) * n // 2 a %= m if b >= m: ret += n * (b // m) b %= m if a * n + b < m: return ret y_max = (a * n + b) // m x_max = y_max * m - b ret += (n - (x_max + a - 1) // a) * y_max n = y_max m, a, b = a, m, -x_max % a input = sys.stdin.buffer.readline T = int(eval(input())) for _t in range(T): N, M, A, B = list(map(int, input().split())) print((floor_sum(N, M, A, B)))
p02560
def floor_sum(n, m, a, b): res = 0 if b >= m: res += n * (b // m) b %= m while True: if a >= m: res += (n - 1) * n * (a // m) // 2 a %= m y_max = (a * n + b) // m if y_max == 0: break x_max = b - y_max * m res += (n + x_max // a) * y_max n, m, a, b = y_max, a, m, x_max % a return res import sys input = sys.stdin.readline for i in range(int(eval(input()))): n, m, a, b = list(map(int, input().split())) print((floor_sum(n, m, a, b)))
# 一番早いのを写経したものを弄ってアルゴリズム勉強のための試し打ち中 def floor_sum(n, m, a, b): res = 0 if b >= m: res += n * (b // m) b %= m while True: if a >= m: res += (n - 1) * n * (a // m) // 2 a %= m y_max = (a * n + b) // m if y_max == 0: break x_max = b - y_max * m res += (n + x_max // a) * y_max n, m, a, b = y_max, a, m, x_max % a return res import sys input = sys.stdin.buffer.readline T = int(eval(input())) res = [''] * T for i in range(T): n, m, a, b = list(map(int, input().split())) res[i] = str(floor_sum(n, m, a, b)) print(('\n'.join(res)))
p02560
def floor_sum(n, m, a, b): res = 0 while True: res += a//m * n * (n-1) // 2 a %= m res += b//m * n b %= m Y = (a*n+b) // m X = Y*m-b if Y == 0: return res res += (n+(-X//a)) * Y n, m, a, b = Y, a, m, -X%a import sys input = sys.stdin.buffer.readline t = int(eval(input())) for _ in range(t): n, m, a, b = list(map(int, input().split())) print((floor_sum(n, m, a, b)))
def floor_sum(n, m, a, b): res = 0 while True: if a >= m: res += a//m * n * (n-1) // 2 a %= m if b >= m: res += b//m * n b %= m Y = (a*n+b) // m X = Y*m-b if Y == 0: return res res += (n+(-X//a)) * Y n, m, a, b = Y, a, m, -X%a import sys input = sys.stdin.buffer.readline t = int(eval(input())) for _ in range(t): n, m, a, b = list(map(int, input().split())) print((floor_sum(n, m, a, b)))
p02560
def floor_sum(n, m, a, b): res = 0 while True: if a >= m: res += a//m * n * (n-1) // 2 a %= m if b >= m: res += b//m * n b %= m Y = (a*n+b) // m X = Y*m-b if Y == 0: return res res += (n+(-X//a)) * Y n, m, a, b = Y, a, m, -X%a import sys input = sys.stdin.buffer.readline t = int(eval(input())) for _ in range(t): n, m, a, b = list(map(int, input().split())) print((floor_sum(n, m, a, b)))
def floor_sum(n, m, a, b): res = 0 while True: if a >= m: res += a//m * n * (n-1) // 2 a %= m if b >= m: res += b//m * n b %= m Y = (a*n+b) // m X = Y*m-b if Y == 0: return res res += (n-(X+a-1)//a) * Y n, m, a, b = Y, a, m, -X%a import sys input = sys.stdin.buffer.readline t = int(eval(input())) for _ in range(t): n, m, a, b = list(map(int, input().split())) print((floor_sum(n, m, a, b)))
p02560
def floor_sum(n,m,a,b): r=0 x,y,z=0,0,0 while 1: if b>=m: x=b//m else: x=0 if a>=m: y=a//m else: y=0 r+=x*n b-=x*m r+=(y*n*(n-1))>>1 a-=y*m x=(a*n+b)//m if x==0: break y=b-x*m z=y//a r+=(n+z)*x a,b,n,m=m,y-z*a,x,a return r for i in range(int(eval(input()))): print((floor_sum(*list(map(int,input().split())))))
import sys S=sys.stdin.readlines() def floor_sum(n,m,a,b): r=0 x,y,z=0,0,0 while 1: if b>=m: x=b//m else: x=0 if a>=m: y=a//m else: y=0 r+=x*n b-=x*m r+=(y*n*(n-1))>>1 a-=y*m x=(a*n+b)//m if x==0: break y=b-x*m z=y//a r+=(n+z)*x a,b,n,m=m,y-z*a,x,a return r for i in range(int(S[0])): print((floor_sum(*list(map(int,S[i+1].split())))))
p02560
def floor_sum(n,m,a,b): ans = n*(b//m) b %= m while True: ans += (n-1)*n*(a//m)//2 a %= m if a*n+b < m: return ans y_max = (a*n + b)//m b -= y_max*m #now we have x_max = -(b//a) ans += (n + b//a)*y_max n = y_max b %= a m,a = a,m import sys readline = sys.stdin.buffer.readline read = sys.stdin.read T = int(readline()) for _ in range(T): n,m,a,b = list(map(int,readline().split())) print((floor_sum(n,m,a,b)))
# coding: utf-8 # Your code here! def floor_sum(n,m,a,b): res = 0 while True: res += ((n-1)*n*(a//m)>>1) + (b//m)*n a %= m b %= m if a*n+b <= m: return res Y = (a*n+b)//m n,m,a,b = Y,a,m, a*n + b - m*Y import sys input = sys.stdin.buffer.readline T = int(eval(input())) for _ in range(T): n,m,a,b = list(map(int,input().split())) print((floor_sum(n,m,a,b)))
p02560
def floor_sum(n, m, a, b): """ sum( (a*i + b)//m ), i = 0..n-1 を返す""" ans = 0 if a >= m: ans += n * (n - 1) * (a // m) // 2 a %= m if b >= m: ans += n * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: return ans ans += (n - (x_max + a - 1) // a) * y_max ans += floor_sum(y_max, a, m, (a - x_max % a) % a) return ans if __name__ == "__main__": import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) T = int(eval(input())) for _ in range(T): ans = floor_sum(*list(map(int, input().split()))) print(ans)
def floor_sum(n, m, a, b): """ sum( (a*i + b) // m ), i = 0..n-1 を返す""" ans = 0 while True: if a >= m: ans += n * (n - 1) * (a // m) // 2 a %= m if b >= m: ans += n * (b // m) b %= m y_max = (a * n + b) // m x_max = y_max * m - b if y_max == 0: break ans += (n - (x_max + a - 1) // a) * y_max n, m, a, b = y_max, a, m, (a - x_max % a) % a return ans if __name__ == "__main__": import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) T = int(eval(input())) for _ in range(T): ans = floor_sum(*list(map(int, input().split()))) print(ans)
p02560
a, b, c = list(map(int, input().split())) # from math import sqrt import decimal a2 = decimal.Decimal(a) b2 = decimal.Decimal(b) c2 = decimal.Decimal(c) a2 = a2.sqrt() b2 = b2.sqrt() c2 = c2.sqrt() # if sqrt(a) + sqrt(b) < sqrt(c): # print('Yes') # else: # print('No') if a2 + b2 < c2: print('Yes') else: print('No')
a, b, c = list(map(int, input().split())) if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2: print('Yes') else: print('No')
p02743
import math from decimal import Decimal a, b, c = list(map(int, input().split())) A = Decimal(str(a))**Decimal('0.5') B = Decimal(str(b))**Decimal('0.5') C = Decimal(str(c))**Decimal('0.5') if A + B < C: print('Yes') else: print('No')
a, b, c = list(map(int, input().split())) #import numpy as np import math #abc_sq = np.sqrt(abc) d = c - a - b if 4*a*b < d**2 and d > 0: print('Yes') else: print('No')
p02743
from decimal import * getcontext().prec = 100000 a,b,c=list(map(int,input().split())) if Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt(): print('Yes') else: print('No')
import math a,b,c=list(map(int,input().split())) if 4*a*b<(c-a-b)*(c-a-b) and c>a+b: print('Yes') else: print('No')
p02743
a, b, c = list(map(int, input().split())) if c-a-b>0 and 4*a*b<(c-a-b)**2: print('Yes') else: print('No')
a, b, c = list(map(int, input().split())) if c-a-b>=0 and 4*a*b<(c-a-b)**2: print('Yes') else: print('No')
p02743
a, b, c = list(map(int, input().split())) l = a * b * 4 r = c - a - b if r < 0 or l >= r ** 2: print("No") else: print("Yes")
A, B, C = list(map(int, input().split())) x = A * B * 4 y = (C - A - B) ** 2 if x < y and C - A - B > 0: print("Yes") else: print("No")
p02743
from decimal import Decimal, getcontext getcontext().prec = 100000 a, b, c = list(map(Decimal, input().split())) print(('Yes' if a.sqrt() + b.sqrt() < c.sqrt() else 'No'))
from decimal import Decimal, getcontext getcontext().prec = 28 a, b, c = list(map(Decimal, input().split())) print(('Yes' if a.sqrt() + b.sqrt() < c.sqrt() else 'No'))
p02743
from decimal import Decimal, getcontext getcontext().prec = 50 a, b, c = list(map(Decimal, input().split())) print(('Yes' if a.sqrt() + b.sqrt() < c.sqrt() else 'No'))
a, b, c = list(map(int, input().split())) if c - a - b <= 0: print('No') elif 4 * a * b < (c - a - b) ** 2: print('Yes') else: print('No')
p02743
from decimal import * A, B, C = list(map(int,input().split())) a = Decimal(A) b = Decimal(B) c = Decimal(C) if a.sqrt() + b.sqrt() < c.sqrt(): print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if 4*a*b < pow(c-a-b, 2) and c-a-b > 0: print("Yes") else: print("No")
p02743
a, b, c = list(map(float, input().split())) from decimal import * getcontext().prec = 50 A = Decimal(a).sqrt() B = Decimal(b).sqrt() C = Decimal(c).sqrt() print(('Yes' if A+B<C else 'No'))
a, b, c = list(map(int, input().split())) if c - a - b <= 0: print('No') else: if 4*a*b < (c - a - b)**2: print('Yes') else: print('No')
p02743
from decimal import * import math a,b,c = list(map(int,input().split())) asq = Decimal(a).sqrt() bsq = Decimal(b).sqrt() csq = Decimal(c).sqrt() if asq + bsq < csq: print('Yes') else: print('No')
from decimal import * a, b, c = list(map(int, input().split())) a = Decimal(a).sqrt() b = Decimal(b).sqrt() c = Decimal(c).sqrt() import math if a + b < c: print('Yes') else: print('No')
p02743
from decimal import Decimal import math a,b,c = list(map(int,input().split())) d = c - a - b if d >0 and pow(d,2) > 4 * a * b: print('Yes') else:print('No')
a,b,c = list(map(int,input().split())) d = c - a - b if d >0 and pow(d,2) > 4 * a * b: print('Yes') else:print('No')
p02743
import math a,b,c = list(map(int, input().split())) x=a**2+b**2+c**2+2*a*b-2*b*c-2*a*c y=4*a*b if c-b-a>0 and x-y>0 : print("Yes") else: print("No")
def Judgement(x,y,z): if z-x-y>0 and (z-x-y)**2-4*x*y>0: return 0 else: return 1 a,b,c=list(map(int,input().split())) ans=Judgement(a,b,c) if ans==0: print("Yes") else: print("No")
p02743
from decimal import Decimal a, b, c = list(map(int, input().split())) def f(x): return Decimal(Decimal(x)**2 + s) / (2 * Decimal(x)) s = a * b # √s x = 2 # 初期値(0以外の値) for i in range(10**4): x = f(x) l = 2 * x + a + b if l < c: print("Yes") else: print("No")
from decimal import Decimal a, b, c = list(map(int, input().split())) def f(x): return Decimal(Decimal(x)**2 + s) / (2 * Decimal(x)) s = a * b # √s x = 2 # 初期値(0以外の値) while True: newX = f(x) if abs(newX - x) < 1e-7: x = newX break x = newX l = 2 * x + a + b if l < c: print("Yes") else: print("No")
p02743
a, b, c = list(map(int, input().split())) s = c - a - b if s < 0: ans = 'No' else: if 4*a*b < s**2: ans = 'Yes' else: ans = 'No' print(ans)
def main(): a, b, c = list(map(int, input().split())) if 4*a*b < pow(c - (a + b), 2): ans = 'Yes' else: ans = 'No' if c - (a + b) <= 0: ans = 'No' print(ans) if __name__ == "__main__": main()
p02743
def mi():return list(map(str,input().split())) from decimal import * a,b,c=mi() getcontext().prec=1500 a=Decimal(a)**Decimal("0.50") b=Decimal(b)**Decimal("0.50") c=Decimal(c)**Decimal("0.50") if c>a+b: print("Yes") else: print("No")
a,b,c=list(map(int,input().split())) d=c-a-b if d<0:print("No");exit() if 4*a*b<d**2: print("Yes") else: print("No")
p02743
from math import sqrt from decimal import * getcontext().prec = 40000 a, b, c = list(map(int, input().split())) tmp = 2 * sqrt(Decimal(a)) * sqrt(Decimal(b)) print(("Yes" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else "No"))
from math import sqrt from decimal import * a, b, c = list(map(int, input().split())) tmp = 2 * sqrt(Decimal(a)) * sqrt(Decimal(b)) print(("Yes" if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt() else "No"))
p02743
from decimal import Decimal A,B,C=list(map(int,input().split())) if (C-A-B)<0: print("No") else: if Decimal(4*A*B)<Decimal((C-A-B)**2): print("Yes") else: print("No")
A,B,C=list(map(int,input().split())) if (C-A-B)<0: print("No") else: if 4*A*B<(C-A-B)**2: print("Yes") else: print("No")
p02743
import decimal a,b,c=(decimal.Decimal(x) for x in input().split()) if a.sqrt() + b.sqrt() < c.sqrt(): print("Yes") else: print("No")
import decimal decimal.getcontext().prec = 28 a,b,c=(decimal.Decimal(x) for x in input().split()) if a.sqrt() + b.sqrt() < c.sqrt(): print("Yes") else: print("No")
p02743
from decimal import * a,b,c=list(map(int,input().split())) a,b,c=Decimal(a),Decimal(b),Decimal(c) if c**Decimal(0.5)>a**Decimal(0.5)+b**Decimal(0.5): print('Yes') else: print('No')
a,b,c=list(map(int,input().split())) if 4*a*b<(c-a-b)**2 and a+b<c: print('Yes') else: print('No')
p02743
from decimal import * def main(): a, b, c = list(map(int, input().split())) ad = Decimal(a).sqrt() bd = Decimal(b).sqrt() cd = Decimal(c).sqrt() if ad + bd < cd: is_big = True else: is_big = False print(('Yes' if is_big else 'No')) if __name__ == '__main__': main()
def main(): a, b, c = list(map(int, input().split())) if c - a - b <= 0: print('No') exit() if 4 * a * b < pow(c - a - b, 2): is_big = True else: is_big = False print(('Yes' if is_big else 'No')) if __name__ == '__main__': main()
p02743
from decimal import * a, b, c = list(map(int, input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
a, b, c = list(map(int,input().split())) f = c - a - b if f > 0 and f ** 2 > 4 * a * b: print('Yes') else: print('No')
p02743
from decimal import Decimal from decimal import * a, b, c = list(map(str, input().split())) getcontext().prec = 500 a = Decimal(a) b = Decimal(b) c = Decimal(c) if a**Decimal("0.5") + b**Decimal("0.5") < c**Decimal("0.5"): print("Yes") else: print("No")
from decimal import Decimal from decimal import * a, b, c = list(map(str, input().split())) #getcontext().prec = 1000 a = Decimal(a) b = Decimal(b) c = Decimal(c) if a**Decimal("0.5") + b**Decimal("0.5") < c**Decimal("0.5"): print("Yes") else: print("No")
p02743
import math from decimal import Decimal a,b,c = [int(x) for x in input().split()] if (Decimal(a).sqrt() + Decimal(b).sqrt()) < Decimal(c).sqrt(): print("Yes") else: print("No")
a,b,c = [int(x) for x in input().split()] if c - a - b < 0: print("No") elif 4 * a * b < (c - a - b) ** 2: print("Yes") else: print("No")
p02743
from decimal import * import math getcontext().prec = 28 a, b, c = list(map(int, input().split())) a = Decimal(a) b = Decimal(b) c = Decimal(c) a = Decimal.sqrt(a) b = Decimal.sqrt(b) c = Decimal.sqrt(c) if a + b < c: print("Yes") else: print("No")
from decimal import * import math getcontext().prec = 50 a, b, c = list(map(int, input().split())) a = Decimal(a) b = Decimal(b) c = Decimal(c) a = Decimal.sqrt(a) b = Decimal.sqrt(b) c = Decimal.sqrt(c) if a + b < c: print("Yes") else: print("No")
p02743
from decimal import * getcontext().prec=1000 a,b,c=list(map(int,input().split())) A=Decimal(a)**Decimal("0.5") B=Decimal(b)**Decimal("0.5") C=Decimal(c)**Decimal("0.5") D= Decimal(10) ** (-100) if A+B+D<C: print("Yes") else: print("No")
a,b,c=list(map(int,input().split())) x=a**2 + b**2 + c**2 - 2*a*b - 2*a*c - 2*b*c if x>0 and a+b-c<0: print("Yes") else: print("No")
p02743
from decimal import Decimal a, b, c = list(map(int, input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print('Yes') else: print('No')
a, b, c = list(map(int, input().split())) if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0: print('Yes') else: print('No')
p02743
from math import sqrt from decimal import * a, b, c = list(map(int, input().split())) getcontext().prec = 100000 if (Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt()): print('Yes') else: print('No')
from math import sqrt a, b, c = list(map(int, input().split())) l = (a ** 2) + (b ** 2) + (c ** 2) r = 2 * (a * b + b * c + c * a) if (c-a-b > 0 and l > r): print('Yes') elif(sqrt(c) == sqrt(a) + sqrt(b)): print('No') else: print('No')
p02743
from math import sqrt from decimal import * a, b, c = list(map(int, input().split())) getcontext().prec = 50000 if (Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt()): print('Yes') else: print('No')
from math import sqrt from decimal import * a, b, c = list(map(int, input().split())) if (Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt()): print('Yes') else: print('No')
p02743
from decimal import Decimal a, b, c = list(map(int, input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if c - a - b <= 0: print("No") else: if (c - a - b) ** 2 - 4 * a * b > 0: print("Yes") else: print("No")
p02743
# Problem C - Sqrt Inequality # 注意:ルートの計算は近似計算によりWAとなってしまう。 # :整数に落とし込んで計算しよう # input process a, b, c = list(map(int, input().split())) # initialization tochu_1 = c - a - b tochu_2 = 4 * a * b # output process if tochu_1>0 and (tochu_1)**2>tochu_2: print("Yes") else: print("No")
# Problem C - Sqrt Inequality # input a, b, c = list(map(int, input().split())) # check is_ok = (a * b)*4 < (c - a - b)**2 and (c-a-b)>0 # output if is_ok: print("Yes") else: print("No")
p02743
from decimal import * a, b, c = list(map(int, input().split())) if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt(): print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if a + b >= c: print("No") else: if (a + b - c) ** 2 > 4 * a * b: print("Yes") else: print("No")
p02743
A, B, C = list(map(int, input().split())) def intSqrt(n): M = int(n**0.5) while (M + 1)**2 <= n: M += 1 for _ in range(4000): n *= 100 M *= 10 for add in range(0, 10)[:: -1]: if (M + add)**2 <= n: M += add break return M if intSqrt(A) + intSqrt(B) < intSqrt(C): print('Yes') else: print('No')
A, B, C = list(map(int, input().split())) def intSqrt(n): M = int(n**0.5) while (M + 1)**2 <= n: M += 1 for _ in range(300): n *= 100 M *= 10 for add in range(0, 10)[:: -1]: if (M + add)**2 <= n: M += add break return M A, B, C = intSqrt(A), intSqrt(B), intSqrt(C) if abs(A + B - C) < 10 or A + B >= C: print('No') else: print('Yes')
p02743
A, B, C = list(map(int, input().split())) def intSqrt(n): M = int(n**0.5) while (M + 1)**2 <= n: M += 1 for _ in range(300): n *= 100 M *= 10 for add in range(0, 10)[:: -1]: if (M + add)**2 <= n: M += add break return M A, B, C = intSqrt(A), intSqrt(B), intSqrt(C) if abs(A + B - C) < 10 or A + B >= C: print('No') else: print('Yes')
a, b, c = list(map(int, input().split())) print(('Yes' if c - a - b >= 0 and (c - a - b)**2 > 4 * a * b else 'No'))
p02743
from sys import stdin from decimal import Decimal,getcontext getcontext().prec = 50 a,b,c = [Decimal(x) for x in stdin.readline().rstrip().split()] if a.sqrt() + b.sqrt() < c.sqrt(): print("Yes") else: print("No")
from sys import stdin a,b,c = [int(x) for x in stdin.readline().rstrip().split()] if 4*a*b < (c-a-b)**2 and (c-a-b) > 0: print("Yes") else: print("No")
p02743
from decimal import Decimal import math a,b,c = list(map(int,input().split())) a = Decimal(a) b = Decimal(b) c = Decimal(c) if (a.sqrt() + b.sqrt()) < c.sqrt(): print("Yes") else: print("No")
a,b,c = list(map(int,input().split())) if c - a - b > 0 and 4*a*b < (c-a-b)**2: print("Yes") else: print("No")
p02743