input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
def main(): N, x, *a = list(map(int, open(0).read().split())) ans = 0 pre = a[0] for i in range(1, N): if x < pre + a[i]: cur = pre + a[i] - x ans += cur a[i] = a[i] - cur if cur < a[i] else 0 pre = a[i] print(ans) return main()...
def main(): N, x, *a = list(map(int, open(0).read().split())) ans = a[0] - x if x < a[0] else 0 pre = min(a[0], x) for i in range(1, N): dif = pre + a[i] - x if 0 < dif: ans += dif a[i] -= dif pre = a[i] print(ans) return main()
p03862
#003 N,x=input().split(" ") s = input().split(" ") list = [] for i in range(int(N)): list.append(int(s[i])) count = 0 if(list[0]>int(x)): count+=list[0]-int(x) list[0]-=list[0]-int(x) for i in range(1,int(N)): temp = list[i]+list[i-1] if(temp>int(x)): count+=temp-int(x) ...
#003 N,x= [int(i) for i in input().split(" ")] list = [int(i) for i in input().split(" ")] count = 0 for i in range(N): if(i==0): if list[i]>x: temp = list[i]-x count+=temp list[i]-=temp else: temp = list[i]+list[i-1]-x if(temp>0): ...
p03862
n,x = list(map(int,input().split())) a = list(map(int,input().split())) res = float('inf') for b in (a,a[::-1]): tmp = 0 for i in range(n-1): if b[i]+b[i+1]>x: tmp += b[i] + b[i+1] - x if b[i]>x: b[i],b[i+1] = x,0 else: b[i...
n,x = list(map(int,input().split())) a = list(map(int,input().split())) res = 0 if a[0]>x: res += a[0] - x a[0] = x if a[-1]>x: res += a[-1] - x a[-1] = x for i in range(n-1): if a[i]+a[i+1]>x: res += a[i] + a[i+1] - x a[i+1] -= a[i] + a[i+1] - x print(res)
p03862
N,x=list(map(int,input().split())) a=list(map(int,input().split())) ans=0 for i in range(N-1): if sum(a[i:i+2])>x: while sum(a[i:i+2])>x: a[i+1]-=1 ans+=1 while sum(a[i:i+2])>x: a[i]-=1 ans+=1 print(ans)
N,x=list(map(int,input().split())) a=list(map(int,input().split())) ans=0 for i in range(N-1): ex=sum(a[i:i+2])-x if ex>0: ans+=ex if a[i+1]>=ex: a[i+1]-=ex else: a[i+1]=0 a[i]-=ex-a[i+1] print(ans)
p03862
N,x=list(map(int,input().split())) A=list(map(int,input().split())) ans=0 pre=0 for i in range(N-1): s=A[i]+A[i+1]-pre ans+=max(0,s-x) pre=min(max(0,s-x),A[i+1]) print(ans)
N, x = list(map(int, input().split())) *A, = list(map(int, input().split())) ans = 0 for i in range(N - 1): w = A[i] + A[i + 1] if w <= x: continue r = max(0, A[i + 1] - (w - x)) l = x - r ans += A[i] - l + A[i + 1] - r A[i + 1] = r print(ans)
p03862
# Beginner 50 C import copy N, x = list(map(int, input().split())) A = list(map(int, input().split())) B = copy.deepcopy(A) for i in range(N-1): while A[i] + A[i+1] > x: if A[i+1] != 0: A[i+1] -= 1 else: A[i] -= 1 cnt = sum(B) - sum(A) print(cnt)
# Beginner 50 C N, x = list(map(int, input().split())) A = list(map(int, input().split())) sum_s = sum(A) for i in range(N-1): s = A[i] + A[i+1] - x if s > 0: A[i+1] = x - A[i] if A[i+1] >= 0: pass else: A[i] = A[i] + A[i+1] A[i+1] = 0 ...
p03862
def calc(ran, count, cans, X): for n in ran: if n == 0: while cans[n+1] + cans[n] > X: cans[n] -= 1 count += 1 continue if n + 1 == N: while cans[n-1] + cans[n] > X: cans[n] -= 1 count += 1 continue while cans[n-1] + cans[n] > X or ca...
# def calc(ran, count, cans, X): # for n in ran: # if n == 0: # while cans[n+1] + cans[n] > X: # cans[n] -= 1 # count += 1 # continue # if n + 1 == N: # while cans[n-1] + cans[n] > X: # cans[n] -= 1 # count += 1 # continue # while can...
p03862
N, x = list(map(int, input().split())) a = list(map(int, input().split())) res = 0 if a[0] > x: res += a[0]-x a[0] = x for i in range(1,N): if a[i-1]+a[i] > x: tmp = a[i]+a[i-1]-x a[i] -= tmp res += tmp print(res)
N,x = list(map(int,input().split())) a = list(map(int,input().split())) res = 0 if a[0]>x: res = a[0]-x a[0] = x for i in range(1,N): tmp = a[i]+a[i-1]-x if tmp > 0: a[i] -= tmp res += tmp print(res)
p03862
N, x = list(map(int, input().split())) a = list(map(int, input().split())) count = 0 for i, c in enumerate(a): try: j = a[i + 1] except IndexError: break while (a[i + 1] + c) > x: if (a[i + 1] + c) == x: break count += 1 a[i + 1] -= 1 else: continue print(count)
N, x = list(map(int, input().split())) a = list(map(int, input().split())) count = 0 for i, c in enumerate(a): try: j = a[i + 1] except IndexError: break while (a[i + 1] + c) > x: if (a[i + 1] + c) == x: break count += abs(x - (a[i + 1] + c)) a[i + 1] -= abs(x - (a[i + 1] + c)) if a[i...
p03862
N, x = list(map(int, input().split())) a = list(map(int, input().split())) candy = min(a[0], x) ans = a[0] - candy a[0] = candy for i in range(1, N): candy += a[i] if candy > x: m = candy - x ans += m a[i] -= m candy -= a[i - 1] + m else: candy -= a[i -...
N, x = list(map(int, input().split())) a = list(map(int, input().split())) candy = min(a[0], x) ans = a[0] - candy a[0] = candy for i in range(1, N): candy = a[i - 1] + a[i] if candy > x: m = candy - x ans += m a[i] -= m print(ans)
p03862
#coding: utf-8 N, X = (int(x) for x in input().split()) A = [int(x) for x in input().split()] diffs = [] for i in range(N-1): diffs.append(A[i]+A[i+1] - X) ret = 0 for i in range(N-1): tmp = min(diffs[i], A[i+1]) ret += tmp diffs[i] -= tmp if i+1 < len(diffs): diffs[i+1] ...
#coding: utf-8 N, X = (int(x) for x in input().split()) A = [int(x) for x in input().split()] ret = 0 for i in range(N-1): if A[i] + A[i+1] > X: tmp = A[i] + A[i+1] - X ret += tmp A[i+1] -= min(A[i+1], tmp) print(ret)
p03862
N, K = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(1, N): candy = A[i] + A[i - 1] # Kより少ないならそのまま if candy < K: continue # 右にあるやつをたべる r = min(A[i], candy - K) candy -= r A[i] -= r ans += r if candy < K: ...
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(N - 1): L = A[i] R = A[i + 1] eat = max(0, L + R - x) ans += eat A[i + 1] = max(0, R - eat) print(ans)
p03862
import bisect n, d, a = list(map(int, input().split())) fox = [None]*n for i in range(n): x, h = list(map(int, input().split())) fox[i] = (x, h) fox.sort() x = [int(fox[i][0]) for i in range(n)] h = [int(fox[i][1]) for i in range(n)] ans = 0 bit = [0]*n for i in range(n): if i != 0: bit[i] +=...
import bisect import sys def main(): input = sys.stdin.readline n, d, a = list(map(int, input().split())) fox = [None]*n for i in range(n): x, h = list(map(int, input().split())) fox[i] = (x, h) fox.sort() x = [int(fox[i][0]) for i in range(n)] h = [int(fox[i][1]) for i in range(n)]...
p02788
import bisect n, d, a = list(map(int, input().split())) fox = [None]*n for i in range(n): x, h = list(map(int, input().split())) fox[i] = (x, h) fox.sort() x = [int(fox[i][0]) for i in range(n)] h = [int(fox[i][1]) for i in range(n)] ans = 0 bit = [0]*n for i in range(n): if i != 0: bit[i] +=...
import sys input = sys.stdin.readline n, d, a = list(map(int, input().split())) fox = [list(map(int, input().split())) for _ in range(n)] fox.sort() sub = [0]*(n+1) def bisect(x): l, r = 0, n while r-l > 1: k = (r+l)//2 if fox[k][0] <= x: l = k else: ...
p02788
import heapq as hq N, D, A = list(map(int,input().split())) m = [] for i in range(N): hq.heappush(m, tuple(map(int,input().split()))) ans = 0 dmg = 0; d = [] while m: X, H = m[0] # if not d or (X <= d[0][0]): if dmg >= H: hq.heappop(m) else: k = (H - d...
import heapq as hq N, D, A = list(map(int,input().split())) m = [] for i in range(N): hq.heappush(m, tuple(map(int,input().split()))) ans = 0 dmg = 0; d = [] while m: X, H = m[0] if not d or (X <= d[0][0]): if dmg < H: k = (H - dmg + A - 1) // A ans += k ...
p02788
from bisect import bisect_right N, D, A = list(map(int, input().split())) xh = sorted([list(map(int, input().split())) for _ in range(N)]) ds = [0]*(N+1) b = 0 for i, (x, h) in enumerate(xh): d = ds[i] if d>=h: continue h -= d times = h//A if h%A==0 else h//A+1 for j in range(i, (bisect_right...
from bisect import bisect_right N, D, A = list(map(int, input().split())) xh = sorted([list(map(int, input().split())) for _ in range(N)]) ds = [0]*(N+2) b = 0 for i, (x, h) in enumerate(xh, 1): ds[i] += ds[i-1] d = ds[i] if d>=h: continue h -= d times = h//A if h%A==0 else h//A+1 ds[i] +=...
p02788
import bisect N, D, A = list(map(int, input().split())) XH = [list(map(int, input().split())) for _ in range(N)] class BIT: def __init__(self, n): # 1-index self.n = n self.dat = [[0] * self.n for _ in range(2)] def _add_body(self, p, i, x): while i < sel...
from bisect import bisect_right N, D, A = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] x = [] h = [] for d, i in sorted(X): x.append(d) h.append(i) ans = 0 k = [-(-v // A) for v in h] y = [0] * (N + 2) for i in range(N): y[i + 1] += y[i] s = ...
p02788
from bisect import bisect_right N, D, A = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] x = [] h = [] for d, i in sorted(X): x.append(d) h.append(i) ans = 0 k = [-(-v // A) for v in h] y = [0] * (N + 2) for i in range(N): y[i + 1] += y[i] s = ...
from bisect import bisect_right N, D, A = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] X.sort() place = [] hps = [] for x, h in X: place.append(x) hps.append(h) buf = [0] * (N + 2) ans = 0 for i in range(N): # Update buf[i + 1] += buf[i] ...
p02788
import sys input = sys.stdin.readline n, d, a = [int(i) for i in input().split()] chk = [] for i in range(n): x, h = [int(i) for i in input().split()] chk.append((x, 0, h)) from heapq import heapify, heappop, heappush heapify(chk) atk_cnt = 0 ans = 0 while chk: x, t, h = heappop(chk) if t == 0:...
def main(): import sys input = sys.stdin.readline n, d, a = [int(i) for i in input().split()] chk = [] for i in range(n): x, h = [int(i) for i in input().split()] chk.append((x, 0, h)) from heapq import heapify, heappop, heappush heapify(chk) atk_cnt = 0; ans = 0 while chk: ...
p02788
import bisect def main(): N,D,A=list(map(int,input().split())) XH=[list(map(int,input().split())) for _ in range(N)] XH.sort() for i in range(N): XH[i][1]=-(-XH[i][1]//A) X=[x for x,a in XH] far=[0]*N for i in range(N): far[i]=bisect.bisect_right(X,X[i]+2*D)-1 ...
import bisect def main(): N,D,A=list(map(int,input().split())) XH=[list(map(int,input().split())) for _ in range(N)] XH.sort() for i in range(N): XH[i][1]=-(-XH[i][1]//A) X=[x for x,a in XH] far=[0]*N for i in range(N): far[i]=bisect.bisect_right(X,X[i]+2*D)-1 ...
p02788
import sys import bisect from operator import itemgetter input = sys.stdin.readline def main(): N, D, A = [int(x) for x in input().split()] XH = [] X = [] for _ in range(N): x, h = [int(x) for x in input().split()] XH.append([x, h, float("inf")]) XH.append([x + 2...
import sys import bisect from operator import itemgetter input = sys.stdin.readline def main(): N, D, A = [int(x) for x in input().split()] XH = [[None] for _ in range(N * 2)] X = [0] * (N * 2) for i in range(N): x, h = [int(x) for x in input().split()] XH[i * 2] = [x, h,...
p02788
import sys import bisect from operator import itemgetter input = sys.stdin.readline def main(): N, D, A = [int(x) for x in input().split()] XH = [[None] for _ in range(N * 2)] X = [0] * (N * 2) for i in range(N): x, h = [int(x) for x in input().split()] XH[i * 2] = [x, h,...
import sys import bisect from operator import itemgetter input = sys.stdin.readline def main(): N, D, A = [int(x) for x in input().split()] XH = [] X = [] R = [0] * (N * 2) for _ in range(N): x, h = [int(x) for x in input().split()] XH.append((x, h)) XH.appe...
p02788
from bisect import bisect_right class SegTree: def __init__(self, a_list, x_list): assert max(a_list) <= 10 ** 7 assert min(a_list) >= 0 self.n = 1 m = max(a_list) while self.n <= m: self.n *= 2 self.dat_a = [0] * (self.n * 2 - 1) s...
from bisect import bisect_right def solve(n, d, a, xh_list): res = 0 xh_list_s = sorted(xh_list, key=lambda x: x[0]) x_list_s = [xh[0] for xh in xh_list_s] h_list_s = [xh[1] for xh in xh_list_s] dmg = 0 wait_list = [0] * (n + 1) for i in range(n): dmg -= wait_list[i] ...
p02788
from collections import deque from bisect import bisect_right from math import ceil N, D, A = list(map(int, input().split())) monsters = [(-1, -1)] for _ in range(N): x, h = list(map(int, input().split())) monsters.append((x, h)) monsters.sort() #print("monsters = {}".format(monsters)) """ どうせ左端のモン...
import sys from collections import deque from bisect import bisect_right from math import ceil def input(): return sys.stdin.readline().strip() N, D, A = list(map(int, input().split())) monsters = [(-1, -1)] for _ in range(N): x, h = list(map(int, input().split())) monsters.append((x, h)) monsters.s...
p02788
n,d,a = list(map(int,input().split())) event = [] for i in range(n): x,h = list(map(int,input().split())) h = (h-1)//a + 1 event.append([x,0,i,h]) for i in range(n): tmp = event[i][0] + 2 * d event.append([tmp,1,i,0]) event.sort() #print(event) use = [0 for _ in range(n)] now = 0 ans = 0 for j i...
n,d,a = list(map(int,input().split())) raw = [] event = [] for i in range(n): x,h = list(map(int,input().split())) event.append([x,0,i,h]) for i in range(n): tmp = event[i][0] + 2 * d event.append([tmp,1,i]) event.sort() #print(event) use = [0 for _ in range(n)] now = 0 ans = 0 for j in range(2*n)...
p02788
n,d,a = list(map(int,input().split())) raw = [] event = [] for i in range(n): x,h = list(map(int,input().split())) event.append([x,0,i,h]) for i in range(n): tmp = event[i][0] + 2 * d event.append([tmp,1,i]) event.sort() #print(event) use = [0 for _ in range(n)] now = 0 ans = 0 for j in range(2*n)...
n,d,a = list(map(int,input().split())) attack = [0 for _ in range(n)] event = [] for i in range(n): x,h = list(map(int,input().split())) h = (h-1)//a+1 event.append([x-d,0,h,i]) event.append([x+d,1,h,i]) event.sort() #print(event) ans = 0 now = 0 for j in range(2*n): x,m,h,i = event[j] if m ==...
p02788
f=lambda:list(map(int,input().split())) n,d,a=f() lt=sorted([tuple(f()) for _ in range(n)]) from collections import * q=deque() c=s=0 for x,h in lt: while q and q[0][0]<x: s+=q.popleft()[1] h-=s if h<1: continue t=-h//a; c-=t; s-=t*a; q.append((x+d*2,t*a)) print(c)
import sys f=lambda:list(map(int,sys.stdin.readline().split())) n,d,a=f() lt=sorted(tuple(f()) for _ in range(n)) from collections import * q=deque() c=s=0 for x,h in lt: while q and q[0][0]<x: s+=q.popleft()[1] h-=s if h<1: continue t=-h//a; c-=t; s-=t*a; q.append((x+d*2,t*a)) print(c)
p02788
#153_F from bisect import bisect_right n, d, a = list(map(int, input().split())) mons = sorted([tuple(map(int, input().split())) for _ in range(n)]) x = [mons[i][0] for i in range(n)] h = [mons[i][1] for i in range(n)] cnt = 0 for i in range(n): if h[i] <= 0: continue idx = bisect_ri...
#153_F from bisect import bisect_right n, d, a = list(map(int, input().split())) mons = sorted([tuple(map(int, input().split())) for _ in range(n)]) x = [mons[i][0] for i in range(n)] h = [mons[i][1] for i in range(n)] damage = [0 for _ in range(n+1)] cnt = 0 for i in range(n): if i > 0: damage[i]...
p02788
import sys,math sr = sys.stdin.readline def I(i=0):return [int(x)-i for x in sr().split()] L1,L2 = [],[] N,D,A = I() for i in range(N): X,H = I() L1.append([X,math.ceil(H/A)]) L1 = sorted(L1) ans = 0 j = 1 L2 = [-1]*N for i in range(N): lim = L1[i][0] + 2*D for k in range(j,N): ...
import sys,math sr = sys.stdin.readline def I(i=0):return [int(x)-i for x in sr().split()] L1,L2 = [],[] N,D,A = I() for i in range(N): X,H = I() L1.append([X,math.ceil(H/A)]) L1 = sorted(L1) j = 1 L2 = [-1]*N for i in range(N): lim = L1[i][0] + 2*D for k in range(j,N): if L1[k][...
p02788
import math n, d, a = list(map(int,input().split())) e = [[] for i in range(n)] for i in range(n): x, h = list(map(int,input().split())) e[i] = [x,h] e.sort() num = 0 for i in range(n): if e[i][1] > 0: k = math.ceil(e[i][1]/a) num += k for j in range(i+1,n): ...
import math n, d, a = list(map(int,input().split())) e = [[] for i in range(n)] for i in range(n): x, h = list(map(int,input().split())) e[i] = [x,h] num = 0 e.sort() sd = [0 for i in range(n)] l = [i for i in range(n)] for i in range(n): for j in range(l[i-1],i): if e[i][0]-e[j][0] <=...
p02788
from math import ceil from bisect import bisect from operator import itemgetter class BIT: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 i += 1 while i > 0: s += self.tree[i] i -= i & -i ...
from math import ceil from bisect import bisect from operator import itemgetter class BIT: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s ...
p02788
N,D,A=list(map(int,input().split())) from heapq import heappop,heappush,heapify B=[] for _ in range(N): x,h=list(map(int,input().split())) B.append((x,h)) heapify(B) c=0 while B: x,h=heappop(B) sup=x+2*D bomb=(h-1)//A+1 temp=[] c+=bomb while B: X,H=heappop(B) ...
N,D,A=list(map(int,input().split())) from heapq import heappop,heappush,heapify B=[] for _ in range(N): x,h=list(map(int,input().split())) B.append((x,h)) heapify(B) dic={} ans=0 atk_cnt=0 while B: x,h=heappop(B) if h==-1: atk_cnt-=dic[x-1] continue if h<=A*atk_cnt...
p02788
# https://atcoder.jp/contests/abc153/tasks/abc153_f # 座標圧縮、貪欲法、imos法 import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_tuple(H): ''' H is number of rows ''' ret = [] for _ in range(H): ret.append(tuple(map(int, re...
# https://atcoder.jp/contests/abc153/tasks/abc153_f # 座標圧縮、貪欲法、imos法 import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_tuple(H): ''' H is number of rows ''' ret = [] for _ in range(H): ret.append(tuple(map(int, re...
p02788
N,D,A = list(map(int,input().split())) X = [] for _ in range(N): x,h = list(map(int,input().split())) X.append([x,h]) X.sort() ans = 0 for i in range(N): h = int(X[i][1]) if h != 0: x = int(X[i][0]) if h % A == 0: count = h // A else: count =...
N,D,A = list(map(int,input().split())) X = [] for _ in range(N): x,h = list(map(int,input().split())) X.append([x,h]) X.sort() if X[-1][0] - X[0][0] < 2 * D: ans = 0 max = 0 for i in range(N): if X[i][1] > max: max = X[i][1] if max % A == 0: ans = max //...
p02788
import sys input = sys.stdin.buffer.readline def main(): n, d, a = list(map(int, input().split())) XH = [] for i in range(n): x, h = list(map(int, input().split())) XH.append((x, h)) XH.sort() from collections import deque q = deque() ans = 0 import copy...
import sys input = sys.stdin.buffer.readline def main(): n, d, a = list(map(int, input().split())) XH = [] for i in range(n): x, h = list(map(int, input().split())) XH.append((x, h)) XH.sort() from collections import deque q = deque() ans = 0 t = 0 ...
p02788
import sys input = sys.stdin.buffer.readline def main(): n, d, a = list(map(int, input().split())) XH = [] for i in range(n): x, h = list(map(int, input().split())) XH.append((x, h)) XH.sort() from collections import deque q = deque() ans = 0 t = 0 ...
class BIT: def __init__(self, n): self.n = n self.bit = [0]*(self.n+1) # 1-indexed def init(self, init_val): for i, v in enumerate(init_val): self.add(i, v) def add(self, i, x): # i: 0-indexed i += 1 # to 1-indexed while i <= self.n: ...
p02788
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from...
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from...
p02788
def binary(N, LIST, num): # 二分探索 # N:探索要素数 l, r = -1, N while r - l > 1: if LIST[(l + r) // 2] > num: # 条件式を代入 r = (l + r) // 2 else: l = (l + r) // 2 return r + 1 n, d, a = list(map(int, input().split())) xh = sorted(list(map(int, input().split())) for...
def binary(N, LIST, num): # 二分探索 # N:探索要素数 l, r = -1, N while r - l > 1: if LIST[(l + r) // 2] > num: # 条件式を代入 r = (l + r) // 2 else: l = (l + r) // 2 return r + 1 n, d, a = list(map(int, input().split())) xh = sorted(list(map(int, input().split())) for...
p02788
from bisect import bisect_right n,d,a=list(map(int,input().split())) xh=[list(map(int,input().split()))for _ in range(n)] xh.sort() x=[] h=[] for xx,hh in xh: x.append(xx) h.append(hh) not_imos=[0]*(n+1) atk_n=0 ans=0 for i in range(n): atk_n-=not_imos[i] h[i]-=atk_n*a if h[i]<0:h[i]=0 atk...
n,d,a=list(map(int,input().split())) d*=2 xh=[list(map(int,input().split()))for _ in range(n)] xh.sort() x=[i for i,j in xh]+[10**20] h=[j for i,j in xh] notimos=[0]*(n+1) c=0 ans=0 from bisect import bisect_right for i in range(n): c+=notimos[i] xx,hh=xh[i] hh=max(0,hh-c*a) m=0--hh//a ans+=m ...
p02788
from operator import itemgetter import bisect N, D, A = list(map(int, input().split())) enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0)) d_enemy = [enemy[0] for enemy in enemies] b_left = bisect.bisect_left logs = [] ans = 0 for i, enemy in enumerate(enemies): X, hp ...
from operator import itemgetter import bisect N, D, A = list(map(int, input().split())) enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0)) d_enemy = [enemy[0] for enemy in enemies] b_left = bisect.bisect_left logs = [] logs_S = [0, ] ans = 0 for i, enemy in enumerate(enemi...
p02788
import bisect import operator import collections class RAQ(): def __init__(self, size): """初期化""" self.size = size n = 2 ** ((size-1).bit_length()) treesize = n * 2 self.st = [0 for i in range(treesize)] @classmethod def from_array(cls, a): ...
import bisect import operator import collections class RAQ(): def __init__(self, size): """初期化""" self.size = size self.sub = [0 for i in range(size + 1)] self.r = 0 self.v = 0 @classmethod def from_array(cls, a): st = cls(len(a)) ...
p02788
import bisect import operator import collections class RAQ(): def __init__(self, size): """初期化""" self.size = size self.sub = [0 for i in range(size + 1)] self.r = 0 self.v = 0 @classmethod def from_array(cls, a): st = cls(len(a)) ...
import bisect import operator import collections import sys input = sys.stdin.readline class RAQ(): def __init__(self, size): """初期化""" self.size = size self.sub = [0 for i in range(size + 1)] self.r = 0 self.v = 0 @classmethod def from_ar...
p02788
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, d, a = list(map(int, readline().split())) xh = [list(map(int, readline().split())) for _ in range(n)] from operator import itemgetter import bisect xh.sort(...
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, d, a = list(map(int, readline().split())) xh = [list(map(int, readline().split())) for _ in range(n)] from operator import itemgetter, add import bisect xh....
p02788
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemge...
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemge...
p02788
n, d, a = list(map(int, input().split())) xh = [] for i in range(n): xi, hi = list(map(int, input().split())) xh.append([xi, hi]) xh.sort(key=lambda x: x[0]) x, h = [], [] for i in range(n): x.append(xh[i][0]) h.append(xh[i][1]) cnt = 0 for i in range(n): xi, hi = x[i], h[i] if ...
n, d, a = list(map(int, input().split())) xh = [] for i in range(n): xi, hi = list(map(int, input().split())) xh.append([xi, hi]) xh.sort(key=lambda x: x[0]) x, h = [], [] for i in range(n): x.append(xh[i][0]) h.append(xh[i][1]) cnt = 0 dmg = [0 for i in range(n+1)] for i in range(n): ...
p02788
class SegmentTree: def __init__(self, N, id, fun):#id:単位元 self.N0 = 2**(N-1).bit_length() self.id = id self.data = [self.id]*(2*self.N0) self.fun = fun def update(self, l, r, val):#[l, r)をvalで更新 l += self.N0 r += self.N0 while l < r: ...
N, D, A = list(map(int, input().split())) XH = [list(map(int, input().split())) for _ in range(N)] XH.sort() X = [XH[i][0] for i in range(N)] ans = 0 res = 0 from bisect import bisect_left cnt = [0]*(N+1) for i in range(N): x, h = XH[i] res-=cnt[i] h-=res if h<=0: continue n ...
p02788
def main(): N, D, A = (int(i) for i in input().split()) P = [[int(i) for i in input().split()] for j in range(N)] P.sort() X = [x[0] for x in P] H = [h[1] for h in P] diff = [H[0]] + [H[i+1] - H[i] for i in range(N-1)] BIT = [0] * (N+1) def BIT_query(idx): """ A1 ~ Aiま...
def main(): N, D, A = (int(i) for i in input().split()) P = [[int(i) for i in input().split()] for j in range(N)] P.sort() X = [x[0] for x in P] H = [h[1] for h in P] diff = [H[0]] + [H[i+1] - H[i] for i in range(N-1)] BIT = [0] * (N+1) def BIT_query(idx): """ A1 ~ Aiま...
p02788
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
p02788
def main(): N, D, A = list(map(int, input().split())) XH = [] for i in range(N): x, h = list(map(int, input().split())) h = (h + (A - 1)) // A XH.append([x, h]) XH.sort() result = 0 for i in range(N): x, h = XH[i] if h < 0: contin...
N, D, A = list(map(int, input().split())) XH = [list(map(int, input().split())) for _ in range(N)] XH.sort() q = [] t = 0 result = 0 for x, h in XH: while True: if len(q) == 0: break if x <= q[0][0]: break t -= q[0][1] q.pop(0) h -= t ...
p02788
N, D, A = list(map(int, input().split())) XH = [list(map(int, input().split())) for _ in range(N)] XH.sort() q = [] t = 0 result = 0 for x, h in XH: while True: if len(q) == 0: break if x <= q[0][0]: break t -= q[0][1] q.pop(0) h -= t ...
N, D, A = list(map(int, input().split())) XH = [list(map(int, input().split())) for _ in range(N)] XH.sort() q = [] t = 0 result = 0 for x, h in XH: while q: if x <= q[0][0]: break t -= q[0][1] q.pop(0) h -= t if h < 0: continue c = (h + A - 1...
p02788
import math,bisect n,d,a = list(map(int,input().split())) lst1 = [list(map(int,input().split())) for i in range(n)] lst1.sort() #解法3 - セグ木 """ ダメージ量をセグ木の区間で管理する。 なお、72行目までセグ木のコードなのでそれ以降を読めば良い。 この解法では、 自分の座標より右側の巻き込める量を調べる ではなく、 自分より右側なんてしったこっちゃ無いので自分より左側のダメージが足りてるかどうかを 逐一確認し、足りないなら自分の座標に必要なだけのダメージを記録する ...
import math,bisect import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n,d,a = list(map(int,readline().split())) lst1 = [list(map(int,readline().split())) for i in range(n)] lst1.sort() #####segfunc###### def segfunc(x,y): return x+y def...
p02788
import bisect N,D,A = list(map(int,input().split())) mons = [] X = []; H = [] need = [0]*N for _ in range(N): x,h = list(map(int,input().split())) mons.append([x,h]) mons = sorted(mons) for i in range(N): X.append(mons[i][0]); H.append(mons[i][1]) need[i] = mons[i][1] // A if mons[...
import bisect N,D,A = list(map(int,input().split())) mons = []; X = []; need = [0]*N; bomb_range = [] for _ in range(N): x,h = list(map(int,input().split())) mons.append([x,h]) mons = sorted(mons) for i in range(N): X.append(mons[i][0]) need[i] = mons[i][1] // A if mons[i][1] % A != ...
p02788
from collections import deque n, d, a = list(map(int, input().split())) monsters = [] for _ in range(n): pos, hp = list(map(int, input().split())) monsters.append([pos, hp]) monsters.sort() bomb_area = deque([]) bomb_power = deque([]) total_damage = 0 ans = 0 for pos, hp in monsters: whi...
from collections import deque import sys input = sys.stdin.readline n, d, a = list(map(int, input().split())) monsters = [] for _ in range(n): pos, hp = list(map(int, input().split())) monsters.append([pos, hp]) monsters.sort() bomb_area = deque([]) bomb_power = deque([]) total_damage = 0 an...
p02788
import sys from collections import deque def I(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LMI(): return list(map(int, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 N, D, A = MI() monsters = list() for i in range(N): x, h = MI() monste...
import sys from bisect import bisect_right def I(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LMI(): return list(map(int, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 N, D, A = MI() monsters = list() for i in range(N): x, h = MI() mons...
p02788
#!/usr/bin/env python3 from math import ceil import heapq def main(): n, d, a = list(map(int, input().split())) q = [] for i in range(n): x, h = list(map(int, input().split())) heapq.heappush(q, (x, 0, ceil(h / a))) bomb = 0 res = 0 while q: x, ty, h = hea...
#!/usr/bin/env python3 from math import ceil import heapq def main(): n, d, a = list(map(int, input().split())) q = [] for i in range(n): x, h = list(map(int, input().split())) heapq.heappush(q, (x, -ceil(h / a))) bomb = 0 res = 0 while q: x, h = heapq.hea...
p02788
import operator import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 class LazySegmentTree: # http://tsutaj.hatenablog.com/entry/2017/03/29/204841 def __init_...
import operator import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(10 ** 9) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 class LazySegmentTree: # http://tsutaj.hatenablog.com/entry/2017/03/29/204841 def __init_...
p02788
import sys import math import bisect input = sys.stdin.readline ceil = math.ceil rbisect=bisect.bisect_right def main(): n,d,a = list(map(int,input().split())) mon = [] for i in range(n): x,h = list(map(int,input().split())) mon.append((x,h)) mon.sort() keys = [ls[0] f...
import sys import math input = sys.stdin.readline ceil = math.ceil def main(): def isok(z,val):##適宜変更 return (z-val<=2*d) def bisect(ls,val): ##valの関数isok(x,val)がTrueとなる一番右のindex を返す 全部Falseなら-1 ok = -1 ng = len(ls) idx = (ok+ng)//2 while ng-ok>1: ...
p02788
N,D,A=[int(x) for x in input().split()] xh = [[int(x) for x in input().split()] for _ in range(N)] xh = sorted(xh) r=0 l=0 ans = 0 mi = 10**9 for l in range(N): if xh[l][1]==0: #print(l) continue la = (xh[l][1]+A-1)//A xh[l][1]=0 r=l for _ in range(N): if l<N and r<N and 2*D>xh[r][0...
N,D,A=[int(x) for x in input().split()] xh = [[int(x) for x in input().split()] for _ in range(N)] xh = sorted(xh) r=0 l=0 ans = 0 mi = 10**9 d = [0]*(N+1) for l in range(N): if d[l]<xh[l][1]: la = (xh[l][1]-d[l]+A-1)//A for _ in range(N): if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]: ...
p02788
from math import ceil from collections import deque N, D, H = list(map(int, input().split())) Monsters = sorted([list(map(int, input().split())) for i in range(N)]) Monsters = [[x, ceil(h/H)] for x, h in Monsters] ans = 0 acc = 0 deq = deque([]) for x, h in Monsters: while deq and x>deq[0][0]: lim...
from collections import deque N, D, A = list(map(int, input().split())) ls = [] for i in range(N): x,h = list(map(int, input().split())) h = h//A if h%A==0 else h//A+1 ls += [(x,h)] ls.sort(key=lambda x:x[0]) deq = deque([]) ans = 0 acc = 0 for i in range(N): x, h = ls[i] while deq and deq[0][0]<...
p02788
import sys from collections import deque sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, d, a = list(map(int, input().split())) XH = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0]) que = deque...
import sys from collections import deque sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, d, a = list(map(int, input().split())) XH = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0]) res = 0 total = 0 end = deque...
p02788
n, d, a = list(map(int,input().split())) x_b = [] x_b2 = [] x = [0]*n h_b = [] h = [0]*n for i in range(n): x_temp,h_temp = list(map(int,input().split())) x_b.append({'key':i, 'val':x_temp}) x_b2.append(x_temp) h_b.append(h_temp) x_b.sort(key = lambda x_b : x_b['val']) for i in range(n)...
import sys input = sys.stdin.readline # 二分木 import bisect n,d,a = list(map(int,input().split())) xh = [list(map(int, input().split())) for _ in range(n)] xh.sort() x = [ tmp[0] for tmp in xh] damage = [0] * (n+1) ans = 0 for i in range(n): damage[i+1] += damage[i] if( damage[i+1] >= xh[i][1]...
p02788
import math import bisect import sys input = sys.stdin.readline N,D,A=list(map(int,input().split())) XH=[[0,0] for _ in range(N)] for i in range(N): x,h=list(map(int,input().split())) XH[i][0]=x XH[i][1]=h XH.sort() X=[0]*N for i in range(N): X[i]=XH[i][0] #bの倍数の中でaを超える最小...
import math import bisect import sys input = sys.stdin.readline N,D,A=list(map(int,input().split())) XH=[[0,0] for _ in range(N)] for i in range(N): x,h=list(map(int,input().split())) XH[i][0]=x XH[i][1]=h XH.sort() X=[0]*N for i in range(N): X[i]=XH[i][0] ans=0 S=[0]*...
p02788
from operator import itemgetter from bisect import bisect_right n, d, a = list(map(int, input().split())) monster = [tuple(map(int, input().split())) for _ in range(n)] monster.sort(key=itemgetter(0)) xx = [xi for xi, hi in monster] ans = 0 imos = [0] * (n + 1) for i, (xi, hi) in enumerate(monster): hi -...
from operator import itemgetter from bisect import bisect_right import sys input = sys.stdin.readline n, d, a = list(map(int, input().split())) monster = [tuple(map(int, input().split())) for _ in range(n)] monster.sort(key=itemgetter(0)) xx = [xi for xi, hi in monster] ans = 0 imos = [0] * (n + 1) for i,...
p02788
N, D, A = list(map(int, input().split())) XH = [list(map(int, input().split())) for _ in range(N)] XH = sorted(XH) for i in range(N): XH[i][1] = (XH[i][1] + A - 1) // A adjust = [0 for _ in range(N + 1)] ans = 0 done = 0 for i in range(N): done -= adjust[i] XH[i][1] -= done if XH[i]...
import sys N, D, A = list(map(int, sys.stdin.readline().split())) XH = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] XH = sorted(XH) for i in range(N): XH[i][1] = (XH[i][1] + A - 1) // A adjust = [0 for _ in range(N + 1)] def findi(v): ng = 0 ok = N while abs(ok - ng...
p02788
from collections import deque from math import ceil import sys input = sys.stdin.readline def main(): N,D,A = list(map(int,input().split())) XH = sorted([[int(i) for i in input().split()] for _ in range(N)],key=lambda x: x[0]) ans = 0 index = deque() damage = 0 for i in range(N): ...
# try AfterContestCase from collections import deque from math import ceil import sys input = sys.stdin.readline def main(): N,D,A = list(map(int,input().split())) XH = sorted([[int(i) for i in input().split()] for _ in range(N)],key=lambda x: x[0]) ans = 0 index = deque() damage = 0 ...
p02788
n,d,a=list(map(int,input().split())) xh=[list(map(int,input().split())) for _ in range(n)] xh.sort() ans = 0 import queue q=queue.Queue() kaisuu = (xh[0][1] +a-1) // a damege = kaisuu*a ans += kaisuu iti = xh[0][0] + 2*d maedame = damege skip =False for i in range(1,n): while(iti < xh[i][0]): ...
n,d,a=list(map(int,input().split())) xh=[list(map(int,input().split())) for _ in range(n)] xh.sort() import collections pq=collections.deque() ans = 0 totalDamage = 0 for i in range(n): x,h = xh[i] while len(pq) > 0 and pq[0][0] < x: totalDamage -= pq[0][1] pq.popleft() h...
p02788
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in...
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in...
p02788
# -*- coding: utf-8 -*- import sys from bisect import bisect_right 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...
# -*- coding: utf-8 -*- import sys from bisect import bisect_right 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...
p02788
import sys sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, D, A = lr() XH = [lr() for _ in range(N)] XH.sort() over = [N] * N # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値(最大はNで対象なし) cur = 1 for i in range(N): w...
import sys sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def main(): N, D, A = lr() XH = [lr() for _ in range(N)] XH.sort() over = [N] * N # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値(最大はNで対象なし) c...
p02788
N, D, a = [int(x) for x in input().split()] XH = [] for _ in range(N): XH.append([int(x) for x in input().split()]) XH.sort() #####segfunc###### def segfunc(x,y): return x + y def init(init_val): #set_val for i in range(n): seg[i+num-1]=init_val[i] #built for i in ra...
import sys input = sys.stdin.readline N, D, a = [int(x) for x in input().split()] XH = [] for _ in range(N): XH.append([int(x) for x in input().split()]) XH.sort() #####segfunc###### def segfunc(x,y): return x + y def init(init_val): #set_val for i in range(n): seg[i+num-1]=in...
p02788
import sys input = sys.stdin.readline N, D, a = [int(x) for x in input().split()] XH = [] for _ in range(N): XH.append([int(x) for x in input().split()]) XH.sort() #####segfunc###### def segfunc(x,y): return x + y def init(init_val): #set_val for i in range(n): seg[i+num-1]=in...
import sys input = sys.stdin.readline N, D, a = [int(x) for x in input().split()] XH = [] for _ in range(N): XH.append([int(x) for x in input().split()]) XH.sort() #####segfunc###### def segfunc(x,y): return x + y def init(init_val): #set_val for i in range(n): seg[i+num-1]=in...
p02788
from collections import deque import sys input = sys.stdin.buffer.readline def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) n, d, a = MAP() xh = [LIST() for i in range(n)] xh = sorted(xh, key=lambda x:(x[0])) q = deque() ca = 0 cnt = 0 for i in range(...
from collections import deque import sys input = sys.stdin.buffer.readline def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) n, d, a = MAP() monster = {} x = [] for i in range(n): xx, hh = MAP() monster[xx] = hh x.append(xx) x.sort() q = ...
p02788
N,D,A=list(map(int,input().split())) L=[] for i in range(N): x,h=list(map(int,input().split())) L.append([x,h]) L.sort() import math ans=0 S=0 P=0 RL=[10**10] RC=[0] cnt=0 for i in range(N): while RL[P]<L[i][0]: cnt+=RC[P] P+=1 if L[i][1]-S+cnt>0: ans+=math....
import sys input=sys.stdin.readline N,D,A=list(map(int,input().split())) L=[] for i in range(N): x,h=list(map(int,input().split())) L.append([x,h]) L.sort() import math ans=0 S=0 P=0 RL=[0] RC=[0] cnt=0 for i in range(N): for j in range(P,len(RL)): if RL[P]<L[i][0]: ...
p02788
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations,groupby import sys import bisect import string import math import time import random def S_(): return input() def LS(): return [i for i in in...
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations,groupby import sys import bisect import string import math import time import random def S_(): return input() def LS(): return [i for i in in...
p02788
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations,groupby import sys import bisect import string import math import time import random def S_(): return input() def LS(): return [i for i in in...
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations,groupby import sys import bisect import string import math import time import random def S_(): return input() def LS(): return [i for i in in...
p02788
N, D, A = list(map(int, input().split())) monster = [] for k in range(N): monster.append(list(map(int, input().split()))) monster.sort(key = lambda x: x[0]) ans = 0 k = 0 while k < len(monster): if monster[k][1] > 0: nowx = monster[k][0] damage = ((monster[k][1]-0.1)//A)*A + A ans += int((mon...
N, D, A = list(map(int, input().split())) monster = [] for k in range(N): monster.append(list(map(int, input().split()))) monster.sort(key = lambda x: x[0]) for k in range(N): monster[k][1] = int((monster[k][1]-0.1)//A + 1) ans = 0 """ k = 0 while k < len(monster): if monster[k][1] > 0: nowx = mon...
p02788
from bisect import bisect_right def getVal(i): # get value of node (i,i) v = T[(i,i)][0] cur = (i,i) cur = T[cur][1] while cur[0]>=0: v += T[cur][0] cur = T[cur][1] return v def udT(i,j,x,node): # add x between [i,j] where current node is given l,r = node[0],node[1] ...
from bisect import bisect_right N,D,A = list(map(int,input().split())) X = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0]) B = [0 for _ in range(N+1)] cnt = 0 cur = 0 delta = 0 flag = 0 while cur<N: x = X[cur][0] h = X[cur][1]+delta if h%A==0: n = h//A e...
p02788
import math def make_tree(n): i = 2 while True: if i >= n * 2: tree = [0] * i break else: i *= 2 return tree def get(i): i += len(tree) // 2 ans = 0 while True: if i == 0: break ans += tree[i] ...
import math def make_tree(n): i = 2 while True: if i >= n * 2: tree = [0] * i break else: i *= 2 return tree def get(i): i += len(tree) // 2 ans = 0 while True: if i == 0: break ans += tree[i] ...
p02788
N, D, A = list(map(int, input().split())) Monster = [0]*N for i in range(N): Monster[i] = list(map(int, input().split())) Monster.sort(key=lambda x:x[0]) from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from collections import deque d = deque() damage = 0 an...
from bisect import * def solve(): ans = 0 N, D, A = list(map(int, input().split())) B = [list(map(int, input().split())) for _ in range(N)] B.sort() lasts = [0]*(N+1) now = 0 for i,((x,h),l) in enumerate(zip(B,lasts)): now -= l atack = max(0,-(-(h-now)//A)) ans += atack damage ...
p02788
from collections import deque import math import bisect n, d, a = list(map(int, input().split())) data = [] x_point = [] for i in range(n): x,h = list(map(int, input().split())) data.append([x,h]) x_point.append(x) data.sort() x_point.sort() imos = [0] * (n+2) ans = 0 for i in range(1,n+1): ...
from collections import deque import math n, d, a = list(map(int, input().split())) data = [] for i in range(n): data.append(list(map(int, input().split()))) data.sort() dam = 0 ans = 0 q = deque() for i in range(n): x,h = data[i] while q: k = q.popleft() if k[1] >= x: ...
p02788
from bisect import bisect_right N, D, A = list(map(int, input().split())) M = [] for i in range(N): x, h = list(map(int, input().split())) M.append((x, -(-h//A))) M.sort(key=lambda x: x[0]) X = list([x[0] for x in M]) H = list([x[1] for x in M]) dmg = [0] * (N+1) ans = 0 for i in range(N): x, h ...
from bisect import bisect_right N, D, A = list(map(int, input().split())) M = [] for i in range(N): x, h = list(map(int, input().split())) M.append((x, -(-h//A))) M.sort(key=lambda x: x[0]) X = list([x[0] for x in M]) H = list([x[1] for x in M]) dmg = [0] * (N+1) ans = 0 for i in range(N): x, h ...
p02788
def main(): from bisect import bisect def _add(data,k,x): while k<=N: data[k]+=x k+=k&-k def add(l,r,x): _add(data0,l,-x*(l-1)) _add(data0,r,x*(r-1)) _add(data1,l,x) _add(data1,r,-x) def _get(data,k): s=0 while ...
from bisect import* def _add(data,k,x): while k<=N: data[k]+=x k+=k&-k def add(l,r,x): _add(data0,l,-x*(l-1)) _add(data0,r,x*(r-1)) _add(data1,l,x) _add(data1,r,-x) def _get(data,k): s=0 while k: s+=data[k] k-=k&-k return s def query(l,r): ...
p02788
import sys def input(): return sys.stdin.readline()[:-1] #import numpy as np import math from bisect import bisect N, D, A = list(map(int, input().split())) xh = [list(map(int, input().split())) for _ in range(N)] xh.sort(key=lambda x: x[0]) x = [i[0] for i in xh] h = [i[1] for i in xh] #h_int = np.c...
#import numpy as np import math from bisect import bisect N, D, A = list(map(int, input().split())) xh = [list(map(int, input().split())) for _ in range(N)] xh.sort(key=lambda x: x[0]) x = [i[0] for i in xh] h = [i[1] for i in xh] #h_int = np.ceil(h/A) cnt=0 damage=[0]*(N+1) for i in range(len(x)): ...
p02788
from heapq import heappush, heappop N, D, A = list(map(int, input().split())) data = [] for _ in range(N): x, h = list(map(int, input().split())) heappush(data, (x, 0, h)) total = 0 height = 0 while data: x, type, h = heappop(data) if type == 0: if height < h: count = (h - height + A - 1) // ...
N, D, A = list(map(int, input().split())) data = [] for _ in range(N): data.append(tuple(map(int, input().split()))) data.sort() queue = [] i = 0 j = 0 total = 0 height = 0 while i < N: if j >= len(queue) or data[i][0] <= queue[j][0]: x, h = data[i] i += 1 if height < h: count = (h - hei...
p02788
import sys sys.setrecursionlimit(500000) def input(): return sys.stdin.readline()[:-1] class BIT: def __init__(self, L): self.N = len(L) self.bit = [0]*self.N for i,l in enumerate(L): self.add(i,l) def add(self, a, w): x = a + 1 ...
import sys sys.setrecursionlimit(500000) def input(): return sys.stdin.readline()[:-1] class DualSegmentTree: def __init__(self, n) : self.n = n self.N0 = 1 << n.bit_length() self.data = [0] * (self.N0*2) def update(self, l, r, val) : l += self.N0 r +...
p02788
import math from heapq import heappop, heappush N, D, A = list(map(int, input().split())) D *= 2 enemies = [] for _ in range(N): x, h = list(map(int, input().split())) enemies.append((x, math.ceil(h / A))) enemies.sort() t = 0 ans = 0 attacks = [] attacksum = 0 for f in range(N): x, h = enem...
import math from heapq import heappop, heappush N, D, A = list(map(int, input().split())) D *= 2 enemies = [] for _ in range(N): x, h = list(map(int, input().split())) enemies.append((x, math.ceil(h / A))) enemies.sort() t = 0 ans = 0 attacks = [] attacksum = 0 for f in range(N): x, h = enem...
p02788
from heapq import heapify, heappush, heappop N, D, A = list(map(int, input().split())) XH = [tuple(map(int, input().split())) for _ in range(N)] heap = [(x, h, True) for x, h in XH] heapify(heap) ans = 0 bomb_effect = 0 while heap: x, h, monster_flg = heappop(heap) if monster_flg: tairyo...
N, D, A = list(map(int, input().split())) XH = [tuple(map(int, input().split())) for _ in range(N)] XH.sort() ans = 0 bomb_effect = 0 bomb_i = 0 bombs = [] for x, h in XH: while (bomb_i < len(bombs)) and (x > bombs[bomb_i][0]): bomb_effect -= bombs[bomb_i][1] * A bomb_i += 1 tai...
p02788
import sys, collections input = sys.stdin.readline N, D, A = [int(_) for _ in input().split()] XH = sorted([[int(_) for _ in input().split()] for _ in range(N)]) R = collections.deque([]) bombs_ = {} for i, xh in enumerate(XH): R += [xh[0] + 2 * D + 1] while R[0] <= xh[0]: bombs_[R.popleft() - ...
import sys, heapq input = sys.stdin.readline N, D, A = [int(_) for _ in input().split()] XH = [[int(_) for _ in input().split()] for _ in range(N)] He = [[2 * x, h, 0] for x, h in XH] heapq.heapify(He) now = 0 ans = 0 while He: x, h, t = heapq.heappop(He) if t: now -= h else: if...
p02788
(N,D,A) = list(map(int,input().split())) l = [] for i in range(N): l.append([int(x) for x in input().split()]) l.sort() k = [0 for i in range(N)] for i in range(N): k[i] = -((-l[i][1])//A) m = [0] * N ub = 0 cnt = 1 for i in range(N): if ub < N-1: while l[ub + 1][0]-l[i][0] <= 2*D...
(N,D,A) = list(map(int,input().split())) l = [] for i in range(N): l.append([int(x) for x in input().split()]) l.sort() k = [0 for i in range(N)] for i in range(N): k[i] = -((-l[i][1])//A) m = [0] * N ub = 0 cnt = 1 for i in range(N): if ub < N-1: while l[ub + 1][0]-l[i][0] <= 2*D: ...
p02788
from math import * import bisect n, d, a = list(map(int, input().split())) p = [] for _ in range(n): p.append(tuple(map(int, input().split()))) p = sorted(p) c=0 for i in range(n): x, h = p[i] if h <= 0: continue m = ceil(h/a) c+=m m = m*a for i in range(i+1, n): if x + d*2 < p[i][0]:...
from math import * n, d, a = list(map(int, input().split())) damage_diff = [0] * n damage = 0 p = sorted(tuple(map(int, input().split())) for _ in range(n)) j = 0 c = 0 for i in range(n): damage -= damage_diff[i] x, h = p[i] h -= damage if h <= 0: continue m = ceil(h/a) c += m m = ...
p02788
from collections import deque def main(): N, D, A = list(map(int, input().split())) XH = [] for _ in range(N): x, h = list(map(int, input().split())) h = (h + A - 1) // A XH.append((x, h)) XH.sort() D *= 2 Q = deque() x0, h0 = XH[0] Q.append((x0, h0)...
from collections import deque def main(): N, D, A = list(map(int, input().split())) XH = [] for _ in range(N): x, h = list(map(int, input().split())) h = (h + A - 1) // A XH.append((x, h)) XH.sort() D *= 2 Q = deque() x0, h0 = XH[0] Q.append((x0 + D,...
p02788
from collections import deque N, D, A = list(map(int, input().split())) X = [] for _ in range(N): x, h = list(map(int, input().split())) X.append((x, h)) X = sorted(X)[::-1] Q = deque([]) ans = 0 k = 0 while X: if len(Q) == 0 or X[-1][0] <= Q[0][0]: x, h = X.pop() h = max(h ...
import sys input = sys.stdin.readline from collections import deque N, D, A = list(map(int, input().split())) X = [] for _ in range(N): x, h = list(map(int, input().split())) X.append((x, h)) X = sorted(X)[::-1] Q = deque([]) ans = 0 k = 0 while X: if len(Q) == 0 or X[-1][0] <= Q[0][0]: ...
p02788
import sys input = sys.stdin.readline from collections import deque from operator import itemgetter key = itemgetter(0) N, D, A = list(map(int, input().split())) X = [] for _ in range(N): x, h = list(map(int, input().split())) X.append((x, h)) X = sorted(X)[::-1] Q = deque([]) ans = 0 k = 0 wh...
import sys input = sys.stdin.readline from collections import deque from operator import itemgetter N, D, A = list(map(int, input().split())) X = [] for _ in range(N): x, h = list(map(int, input().split())) X.append((x, h)) X = sorted(X, key = itemgetter(0))[::-1] Q = deque([]) ans = 0 k = 0 wh...
p02788
import sys input = sys.stdin.readline from collections import deque N, D, A = list(map(int, input().split())) X = [] for _ in range(N): x, h = list(map(int, input().split())) X.append((x, h)) X = sorted(X, key = lambda x: x[0])[::-1] Q = deque([]) ans = 0 k = 0 while X: if len(Q) == 0 or X[...
import sys input = sys.stdin.readline from collections import deque from operator import itemgetter N, D, A = list(map(int, input().split())) X = [] for _ in range(N): x, h = list(map(int, input().split())) X.append((x, h)) X = sorted(X, key = itemgetter(0))[::-1] Q = deque([]) ans = 0 k = 0 wh...
p02788
import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy # import heapq import decimal # import statistics import queue # import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 ...
import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy # import heapq import decimal # import statistics import queue # import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 ...
p02788
import bisect class SegTree: def __init__(self, N): self.N = N self.data = [0] * (2 * N) def update(self, i, x): i += self.N - 1 self.data[i] = x while i > 0: i = (i - 1) // 2 v = self.data[2 * i + 1] + self.data[2 * i + 2] ...
import bisect def main(): N, D, A = list(map(int, input().split())) monsters = [list(map(int, input().split())) for _ in range(N)] monsters.sort() X = [m[0] for m in monsters] # 端から貪欲に攻撃していく ans = 0 damages = [0] * (N + 1) for n, monster in enumerate(monsters): x, h...
p02788
from heapq import heapify, heappop, heappush import sys input = lambda: sys.stdin.readline().rstrip() inpl = lambda: tuple(map(int,input().split())) N, D, A = inpl() q = [] for _ in range(N): x, h = inpl() q.append((x, 0, h)) heapify(q) ans = 0 d = 0 while q: x, s, h = heappop(q) if s == 0...
import sys input = lambda: sys.stdin.readline().rstrip() inpl = lambda: list(map(int,input().split())) Xmax = 10**10 N, D, A = inpl() XH = [inpl() for _ in range(N)] XH.sort() XH.append([Xmax,0]) ans = 0 d = 0 i = j = 0 R = [] while True: if j >= len(R) or XH[i][0] <= R[j][0]: x, h = XH[i] ...
p02788
import bisect n, d, a = [int(i) for i in input().split()] xh = [] for i in range(n): xh.append([int(i) for i in input().split()]) # 座標でソート xh.sort() x = [xh[i][0] for i in range(n)] h = [xh[i][1] for i in range(n)] # i番目のモンスターに、i-k番目で使った爆弾が届いた場合の最小のi-k bomb_bisect = [] for i in range(n): b...
n, d, a = [int(i) for i in input().split()] xh = [] for i in range(n): xh.append([int(i) for i in input().split()]) # 座標でソート xh.sort() x = [xh[i][0] for i in range(n)] h = [xh[i][1] for i in range(n)] # i番目のモンスターに、i-k番目で使った爆弾が届いた場合の最小のi-k # bisectより尺取り法のほうが圧倒的に速いだろjk bomb_syakutori = [0 for i in ran...
p02788
import bisect n, d, a = [int(i) for i in input().split()] xh = [] for i in range(n): xh.append([int(i) for i in input().split()]) # 座標でソート xh.sort() x = [xh[i][0] for i in range(n)] h = [xh[i][1] for i in range(n)] # i番目のモンスターに、i-k番目で使った爆弾が届いた場合の最小のi-k bomb_bisect = [] for i in range(n): b...
import math n, d, a = [int(i) for i in input().split()] xh = [] for i in range(n): xh.append([int(i) for i in input().split()]) # 座標でソート xh.sort() x = [xh[i][0] for i in range(n)] h = [math.ceil(xh[i][1]/a) for i in range(n)] # i番目のモンスターに、i-k番目で使った爆弾が届いた場合の最小のi-k # bisectより尺取り法のほうが速いと思ったんだけど… bomb_...
p02788
import math import bisect n,d,a = list(map(int,input().split())) L = [] kyo = [] s = 0 for i in range(n): x,h = list(map(int,input().split())) L.append([x,h]) kyo.append(x) s += h L.sort() kyo.sort() ans = 0 temp = 0 while s != 0: if L[temp][1] != 0: times = int(math.ceil(L[...
import math import bisect n,d,a = list(map(int,input().split())) L = [] kyo = [] for i in range(n): x,h = list(map(int,input().split())) L.append([x,h]) kyo.append(x) L.sort() kyo.sort() ans = 0 imos = [0]*(n+1) cur = 0 ran = 2*d for i in range(n): if imos[cur] < L[cur][1]: t = ...
p02788