input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
def get_collision(A,ans):
A.sort()
nowkey = -10**10
prevcoor = -10**10
ret = ans[0]
for key, coor, a in A:
if key != nowkey:
if a == 1:
nowkey = key
prevcoor = coor
continue
else:
continue
... | N = int( eval(input()))
XYU = [ tuple( input().split()) for _ in range(N)]
U = []
R = []
D = []
L = []
for x, y, u in XYU:
x, y = int(x), int(y)
if u == "U":
U.append((x,y))
elif u == "D":
D.append((x,y))
elif u == "L":
L.append((x,y))
else:
R.append((x... | p02605 |
N = int( eval(input()))
XYU = [ tuple( input().split()) for _ in range(N)]
U = []
R = []
D = []
L = []
for x, y, u in XYU:
x, y = int(x), int(y)
if u == "U":
U.append((x,y))
elif u == "D":
D.append((x,y))
elif u == "L":
L.append((x,y))
else:
R.append((x... | N=int(eval(input()))
XYU=[tuple(input().split()) for _ in range(N)]
U=[]
R=[]
D=[]
L=[]
for x,y,u in XYU:
x,y = int(x),int(y)
if u=="U":
U.append((x,y))
elif u=="D":
D.append((x,y))
elif u=="L":
L.append((x,y))
else:
R.append((x,y))
ans=[10**9]
def z(... | p02605 |
N=int(eval(input()))
XYU=[tuple(input().split()) for _ in range(N)]
U=[]
R=[]
D=[]
L=[]
for x,y,u in XYU:
x,y = int(x),int(y)
if u=="U":
U.append((x,y))
elif u=="D":
D.append((x,y))
elif u=="L":
L.append((x,y))
else:
R.append((x,y))
ans=[10**9]
def z(A):
A.sort()
n=p=-10**9
for k,c,a... | N=int(eval(input()))
XYU=[tuple(input().split()) for _ in range(N)]
U=[]
R=[]
D=[]
L=[]
for x,y,u in XYU:
x,y = int(x),int(y)
if u=="U":
U.append((x,y))
elif u=="D":
D.append((x,y))
elif u=="L":
L.append((x,y))
else:
R.append((x,y))
ans=10**9
def z(A):
global ans
A.sort()
n=p=-10**9
... | p02605 |
#root.search(x): ◯.data == x のものが存在するある場合それを出力、ない場合Noneを出力
#root.insert(x): ◯.data == xが存在する場合Falseを出力、ない場合◯.data == x なる頂点を作る
#y.to_s(): 頂点yのdataを出力
#y.left_s(): 頂点yのleftを出力(ない場合はNone)
#root.search_lower(x,None): ○.dataがxより小さいものの中で最も大きいものを出力、ない場合Noneを出力
#root.search_higher(x,None): xより大きいものの中で最も小さいものを出力、ない場合Noneを... | import sys
input = sys.stdin.readline
from collections import defaultdict
from bisect import bisect_right
n = int(eval(input()))
a = [list(input().split()) for i in range(n)]
for i in range(n):
if a[i][2] == "R":
a[i][2] = 1
elif a[i][2] == "L":
a[i][2] = 2
elif a[i][2] == "U" :
... | p02605 |
import heapq
import copy
n = int(eval(input()))
size = 2*10**5
def f(ary):
t_ans = 10**100
for i in range(len(ary)):
t_ud = ary[i]
if len(t_ud) != 0:
#print(t_ud)
t_ud.sort()
t_u = -10**100
for j in range(len(t_ud)):
... | import heapq
import copy
n = int(eval(input()))
size = 2*10**5
def f(ary):
t_ans = 10**100
for i in range(len(ary)):
t_ud = ary[i]
if len(t_ud) != 0:
#print(t_ud)
t_ud.sort()
t_u = -10**100
for j in range(len(t_ud)):
... | p02605 |
n = int(eval(input()))
from collections import defaultdict
import bisect
xd0=defaultdict(list)
xd90=defaultdict(list)
xd180=defaultdict(list)
xd270=defaultdict(list)
xyd0=defaultdict(list)
xyd90=defaultdict(list)
xyd180=defaultdict(list)
xyd270=defaultdict(list)
def rotate(x,y,u):
if u=='U': u0='R'
... | n = int(eval(input()))
from collections import defaultdict
import bisect
xd0=defaultdict(list)
xd90=defaultdict(list)
xd180=defaultdict(list)
xd270=defaultdict(list)
xyd0=defaultdict(list)
xyd90=defaultdict(list)
xyd180=defaultdict(list)
xyd270=defaultdict(list)
def rotate(x,y,u):
if u=='U': u0='R'
... | p02605 |
n = int(eval(input()))
from collections import defaultdict
import bisect
xd0=defaultdict(list)
xd90=defaultdict(list)
xd180=defaultdict(list)
xd270=defaultdict(list)
xyd0=defaultdict(list)
xyd90=defaultdict(list)
xyd180=defaultdict(list)
xyd270=defaultdict(list)
def rotate(x,y,u):
if u=='U': u0='R'
... | import sys
input = sys.stdin.readline
n = int(eval(input()))
from collections import defaultdict
import bisect
xd0=defaultdict(list)
xd90=defaultdict(list)
xd180=defaultdict(list)
xd270=defaultdict(list)
xyd0=defaultdict(list)
xyd90=defaultdict(list)
xyd180=defaultdict(list)
xyd270=defaultdict(list)
def ... | p02605 |
n = int(eval(input()))
dic_up = {}
dic_down = {}
dic_hor = {}
dic_ver = {}
lst = []
for i in range(n):
xi, yi, ui = input().split()
xi, yi = int(xi), int(yi)
up = xi - yi
down = xi + yi
if (ui, up) in dic_up:
dic_up[(ui, up)].append(xi)
else:
dic_up[(ui, up)] = [x... | def x_ijo_min(lst, x):
if lst[0] >= x: return lst[0]
left = 0 # xより小さい
right = len(lst) # x以上
while left+1 < right:
mid = (left+right) // 2
if lst[mid] < x:
left = mid
else:
right = mid
if right == len(lst): return False
else: return lst... | p02605 |
_, *a = list(map(str.split, open(0)))
U, R, D, L = "URDL"
INF = float("inf")
d = {}
for *z, u in a:
d.setdefault(u, []).append([*list(map(int, z))])
N = INF
for A, B, S in [(U, D, "x, y"), (R, L, "y, x"),
(R, U, "x+y, x-y"), (D, L, "x+y, x-y"),
(U, L, "x-y, x+y"), (R, D, "x-... | _,*a=list(map(str.split,open(0)))
U,R,D,L="URDL"
d={i:[]for i in"URDL"}
for *z, u in a:d[u]+=[*list(map(int, z))],
N=9e9
P,M="x+y,","x-y,"
for A,B,S in(U,D,"x,y,"),(R,L,"y,x,"),(R,U,P+M),(D,L,P+M),(U,L,M+P),(R,D,M+P):
n=p=-9e9
for x,y,r in sorted(eval(f"[({S}Q)for P,Q in[(A,1),(B,0)]for x,y in d[P]]")):
if... | p02605 |
_,*a=list(map(str.split,open(0)))
U,R,D,L="URDL"
d={i:[]for i in"URDL"}
for *z,u in a:d[u]+=[*list(map(int,z))],
N=9e9
P,M="x+y,","x-y,"
for A,B,S in(U,D,"x,y,"),(R,L,"y,x,"),(R,U,P+M),(D,L,P+M),(U,L,M+P),(R,D,M+P):
n=p=-9e9
for x,y,r in sorted(eval(f"[({S}Q)for P,Q in[(A,1),(B,0)]for x,y in d[P]]")):
if x... | U,R,D,L="URDL"
d={i:[]for i in"URDL"}
_,*a=list(map(str.split,open(0)))
for*z,u in a:d[u]+=[*list(map(int,z))],
N,P,M=9e9,"x+y,","x-y,"
for A,B,S in(U,D,"x,y,"),(R,L,"y,x,"),(R,U,P+M),(D,L,P+M),(U,L,M+P),(R,D,M+P):
n=p=-9e9
for x,y,r in sorted(eval(f"[({S}Q)for P,Q in[(A,1),(B,0)]for x,y in d[P]]")):
if x-n... | p02605 |
U,R,D,L="URDL"
d={i:[]for i in"URDL"}
_,*a=list(map(str.split,open(0)))
for*z,u in a:d[u]+=[*list(map(int,z))],
N,P,M=9e9,"x+y,","x-y,"
for*F,S in(D,U,"x,y,"),(L,R,"y,x,"),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
n=p=-9e9
for x,y,r in sorted(eval(f"[({S}Q)for Q,P in enumerate(F)for x,y in d[P]]")):
if r:n,p... | U,R,D,L="URDL"
d={i:[]for i in"URDL"}
_,*a=list(map(str.split,open(0)))
for*z,u in a:d[u]+=[*list(map(int,z))],
I=N=9e9;P,M="x+y,","x-y,"
for*F,S in(D,U,"x,y,"),(L,R,"y,x,"),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
n=p=-I
for x,y,r in sorted(eval(f"[({S}Q)for Q,P in enumerate(F)for x,y in d[P]]")):
if r:n,p... | p02605 |
U,R,D,L="URDL"
d={i:[]for i in"URDL"}
_,*a=list(map(str.split,open(0)))
for*z,u in a:d[u]+=[*list(map(int,z))],
I=N=9e9;P,M="x+y,","x-y,"
for*F,S in(D,U,"x,y,"),(L,R,"y,x,"),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
n=p=-I
for x,y,r in sorted(eval(f"[({S}Q)for Q,P in enumerate(F)for x,y in d[P]]")):
if r:n,p... | s="URDL";d={i:[]for i in s}
_,*a=list(map(str.split,open(0)))
for*z,u in a:d[u]+=[*list(map(int,z))],
I=N=9e9;P,M="x+y,","x-y,"
for*F,S in(2,0,"x,y,"),(3,1,"y,x,"),(0,1,P+M),(3,2,P+M),(3,0,M+P),(2,1,M+P):
n=p=-I
for x,y,r in sorted(eval(f"(({S}Q)for Q,P in enumerate(F)for x,y in d[s[P]])")):
if r:n,p=x,y
... | p02605 |
INF = 2000000000
def calc_xx(A, B, mult, k, diff_func):
AA = list(sorted(A, key=lambda pp: pp[k]))
BB = list(sorted(B, key=lambda pp: pp[k]))
a = 0
b = 0
min_time = INF
while a < len(A) and b < len(B):
# 衝突判定 (ソートの重複値の全組み合わせで検証)
if AA[a][k] == BB[b][k]:
... | INF = 2000000000
def calc_xx(A, B, mult, comp_field, diff_field):
AA = list(sorted(A, key=lambda pp: (pp[comp_field], pp[diff_field])))
BB = list(sorted(B, key=lambda pp: (pp[comp_field], pp[diff_field])))
a = 0
b = 0
min_time = INF
while a < len(A) and b < len(B):
# 衝突判定... | p02605 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, ... | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, ... | p02605 |
# -*- coding: utf-8 -*-
import sys
import io
def main():
N = int( sys.stdin.readline() )
XYU_list = []
for _ in range(N):
x,y,u = sys.stdin.readline().rstrip().split()
XYU_list.append( [int(x),int(y),u] )
check_UD = {}
check_LR = {}
check_UR = {}
... | # -*- coding: utf-8 -*-
import sys
import io
def main():
N = int( sys.stdin.readline() )
XYU_list = []
for _ in range(N):
x,y,u = sys.stdin.readline().rstrip().split()
XYU_list.append( [int(x),int(y),u] )
diff = float("inf")
# check(1) rotate 0 degree
ret... | p02605 |
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
N = int(eval(input()))
S = 'RULD'
class Plane:
__slots__ = ('x', 'y', 'd')
def __init__(s, x, y, d):
s.x, s.y, s.d = int(x), int(y), d
def __lt__(s, o):
return s.x < o.x
def rotate(s):
... | import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
N = int(eval(input()))
S = 'RULD'
class Plane:
__slots__ = ('x', 'y', 'd')
def __init__(s, x, y, d):
s.x, s.y, s.d = int(x), int(y), d
def __lt__(s, o):
return s.x < o.x
def rotate(s):
... | p02605 |
from collections import defaultdict
from bisect import *
def into_dict(dics,x,y,u):
x,y = int(x),int(y)
insort(dics[u+'_x'][x],y)
insort(dics[u+'_y'][y],x)
insort(dics[u+'_xpy'][x+y],x)
insort(dics[u+'_ymx'][y-x],x)
return dics
def para(dics,dic1,dic2):
ans = float('inf')
for k,v in list(... | from collections import defaultdict
from bisect import *
def into_dict(dics,x,y,u):
x,y = int(x),int(y)
insort(dics[u+'_x'][x],y)
insort(dics[u+'_y'][y],x)
insort(dics[u+'_xpy'][x+y],x)
insort(dics[u+'_ymx'][y-x],x)
return dics
def para(dics,dic1,dic2):
ans = float('inf')
for k,v in list(... | p02605 |
I=N=9**9
P,M,L,R,U,*D='x+y,','x-y,',[],[],[]
for t in[*open(0)][1:]:*z,u=t.split();exec(u+'+=[*map(int,z)],')
for*A,S in(D,U,'x,y,'),(L,R,'y,x,'),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
n=p=-I
for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in P)'%S):
if r:n,p=x,y
elif x==n:N=min(N,y-p)
pri... | I=N=9**9
d=[[],[],[],[]]
for t in[*open(0)][1:]:
*z,u=t.split()
d[ord(u)%5]+=[*list(map(int,z))],
f=lambda x,y:x
g=lambda x,y:y
h=lambda x,y:x+y
i=lambda x,y:x-y
for*A,f,g in(3,0,f,g),(1,2,g,f),(0,2,h,i),(1,3,h,i),(1,0,i,h),(3,2,i,h):
n=p=-I
for x,y,r in sorted((f(x,y),g(x,y),Q)for Q,P in enumerate(A... | p02605 |
I,*U=N,*D,=9**9,
P,*L='x+y,',
M,*R='x-y,',
for t in[*open(0)][1:]:*z,u=t.split();exec(u+'+=[*map(int,z)],')
for*A,S in(D,U,'x,y,'),(L,R,'y,x,'),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
n=I
for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in P)'%S):exec(r*'n,p=x,y'or'N=min(N,y-p)'*(x==n))
print((... | I,*U=N,*D=9**9,
P,*L='x+y,',
M,*R='x-y,',
for t in[*open(0)][1:]:*z,u=t.split();exec(u+'+=[*map(int,z)],')
for*A,S in(D,U,'x,y,'),(L,R,'y,x,'),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in P)'%S):
if r:S,p=x,y
elif x==S:N=min(N,y-p)
print((N%I*5or... | p02605 |
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, = list(map(int, readline().split()))
M = 2*10**5+2
Uy = [[] for _ in range(M)]
Dy = [[] for _ in range(M)]
Rx = [[] for _ in range(M)]
Lx = [[] for _ in range(M)]
d1U = {} # 右上、x+y UR
d1R = {} # 右上、x+... | # coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n, = list(map(int, readline().split()))
M = 2*10**5+2
Uy = {}
Dy = {}
Rx = {}
Lx = {}
d1U = {} # 右上、x+y UR
d1R = {} # 右上、x+y UR
d2U = {} # 左上、x-y UL
d2L = {} # 左上、x-y UL
d3L = {} # 左下、x+y LD
d3D = {} #... | p02605 |
n,m=[ord(i) for i in input().split()];n-=m;print((['<','>'][n>0] if n else'=')) | n,m=input().split();print((['=',['<','>'][n>m]][n!=m])) | p03547 |
x, y = input().split()
if x < y:
print("<")
elif x == y:
print("=")
else:
print(">") | x, y = input().split()
print(("<" if x < y else "=" if x == y else ">")) | p03547 |
X, Y =input().split()
X = int(X, 16)
Y = int(Y, 16)
if(X<Y):
print('<')
elif(X>Y):
print('>')
else:
print('=') | X, Y =input().split()
X = int(X, 16)
Y = int(Y, 16)
print((['=', '<', '>'][(X<Y) - (Y<X)]))
| p03547 |
def tonum(a):
if a == 'A':
return 10
elif a == 'B':
return 11
elif a == 'C':
return 12
elif a == 'D':
return 13
elif a == 'E':
return 14
elif a == 'F':
return 15
else:
return int(a)
a, b = input().split()
a = tonum(a)
... | a, b = list(map(str, input().split()))
if a < b:
print('<')
elif a > b:
print('>')
else:
print('=') | p03547 |
from operator import sub; print(('<<<<<=>>>>>'[sub(*[int(s, 16) for s in (input().split())])+5]))
| print(('<<<<<=>>>>>'[(lambda a,b:a-b)(*list(map(ord,(input().split()))))+5])) | p03547 |
X, Y = list(map(str, input().split()))
if X == 'A':
x = 10
elif X == 'B':
x = 11
elif X == 'C':
x = 12
elif X == 'D':
x = 13
elif X == 'E':
x = 14
elif X == 'F':
x = 15
if Y == 'A':
y = 10
elif Y == 'B':
y = 11
elif Y == 'C':
y = 12
elif Y == 'D':
y = 13
el... | A, B = input().split()
if A > B:
print('>')
elif A == B:
print('=')
else:
print('<')
| p03547 |
# -*- coding: utf-8 -*-
def main():
dict = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}
x, y = input().split()
if dict[x] > dict[y]:
print('>')
elif dict[x] < dict[y]:
print('<')
else:
print('=')
if __name__ == '__main__':
main() | # -*- coding: utf-8 -*-
dic = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}
def func(x, y):
if dic[x] > dic[y]:
result = '>'
elif dic[x] < dic[y]:
result = '<'
else:
result = '='
return result
X, Y = input().split()
print((func(X, Y))) | p03547 |
a,b=input().split();print(([[">","="][ord(a)==ord(b)],"<"][ord(a)<ord(b)])) | x,y=input().split();print(("=><"[(x>y)-(x<y)])) | p03547 |
X,Y = input().split()
c = {"A":11,"B":12,"C":13,"D":14,"E":15,"F":16}
if c[X]== c[Y]:
print("=")
elif c[X] > c[Y]:
print(">")
else:
print("<") | X,Y = input().split()
if X > Y:
print(">")
elif X < Y:
print("<")
else:
print("=") | p03547 |
a,b=input().split();print((['=','<','>'][(a!=b)+(a>b)])) | a,b=input().split();print(("=<>"[(a!=b)+(a>b)])) | p03547 |
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
d... | import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
d... | p03081 |
import sys
input=sys.stdin.readline
n,q=list(map(int,input().split()))
s=input().rstrip()
td=[]
for _ in range(q):
t,d=input().split()
td.append((t,d))
l=-1;r=n+1
while r-l>1:#l以上r未満
mid=(l+r)//2
now=mid
if not 0<=now<n:
if now==-1:
l=mid
else:
r=mid
break
for i in range(q):
if s[... | import sys
input=sys.stdin.readline
n,q=list(map(int,input().split()))
s=input().rstrip()
td=[]
for _ in range(q):
t,d=input().split()
td.append((t,d))
l=-1;r=n+1
while r-l>1:#l以上r未満
mid=(l+r)//2
now=mid
if not 0<=now<n:
if now==-1:
l=mid
else:
r=mid
continue
for i in range(q):
if... | p03081 |
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): r... | #!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(... | p03081 |
import sys
from collections import defaultdict
from string import ascii_uppercase
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()
N,Q = read_int()
s = read_str()
td = [list(read_str().split()) for _ in range(Q)]
d = defaultdict(list)... | import sys
from collections import defaultdict
from string import ascii_uppercase
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()
N,Q = read_int()
s = read_str()
td = [list(read_str().split()) for _ in range(Q)]
lr = {"L":-1, "R":1}
... | p03081 |
DEBUG = False
def get_pos(index):
"""初期位置indexのロボットのクエリ後の配置を返す
is_whick_sideの返り値として返す"""
if DEBUG: print()
iws = is_whick_side(index)
if iws != 0:
if DEBUG: print(iws)
return iws
for t, d in e:
if DEBUG: print(index, s[index], t, d, end='')
if t == ... | DEBUG = False
def get_pos(index):
"""初期位置indexのロボットのクエリ後の配置を返す
is_whick_sideの返り値として返す"""
if DEBUG: print()
iws = -1 if index == -1 else 1 if index == N else 0
if iws != 0:
if DEBUG: print(iws)
return iws
for t, d in e:
if DEBUG: print(index, s[index], t, d, ... | p03081 |
import sys
input = sys.stdin.readline
import bisect
sys.setrecursionlimit(10**8)
N,Q=list(map(int,input().split()))
S=input().strip()
S=[ord(s)-65 for s in S]
M=[input().split() for i in range(Q)]
MLIST=[[] for i in range(26)]
for i in range(Q):
m,lr=M[i][0],M[i][1]
MLIST[ord(m)-65].append(i)
... | import sys
input = sys.stdin.readline
N,Q=list(map(int,input().split()))
S=input().strip()
M=[input().split() for i in range(Q)]
PLACE=-1
for i in range(Q-1,-1,-1):
if PLACE+1<N and M[i][0]==S[PLACE+1] and M[i][1]=="L":
PLACE+=1
elif PLACE>=0 and M[i][0]==S[PLACE] and M[i][1]=="R":
... | p03081 |
def main():
def solve(mid,g):
for t,d in zip(x,y):
if s[mid]==t:
mid-=(d<'R')or-1
if mid==g:
return 1
return 0
n,q,s,*z=open(0).read().split()
x,y=z[::2],z[1::2]
n,q=int(n),int(q)
s=' %s '%s
ok=0
ng=n+1
... | def main():
def solve(mid,g):
for t,d in zip(x,y):
if s[mid]==t:
mid-=(d<'R')or-1
return mid==g
n,q,s,*z=open(0).read().split()
x,y=z[::2],z[1::2]
n,q=int(n),int(q)
s=' %s '%s
ok=0
ng=n+1
while abs(ok-ng)>1:
mid=(ok+ng)//2
... | p03081 |
def main():
def solve(mid,g):
for t,d in zip(x,y):
if s[mid]==t:
mid-=(d<'R')or-1
if mid==g:
return 1
return 0
n,q,s,*z=open(0).read().split()
x,y=z[::2],z[1::2]
n,q=int(n),int(q)
s=' %s '%s
ok=0
ng=... | I=input;n,q=list(map(int,I().split()));s=' %s '%I();l,r=0,n+1
for t,_,d in eval('I(),'*q)[::-1]:L,R=d<'R',d>'L';l+=(t==s[l+1])*L-(t==s[l])*R;r+=(t==s[r])*L-(t==s[r-1])*R
print((max(0,r-l-1))) | p03081 |
I=input;n,q=list(map(int,I().split()));s=' %s '%I();l,r=0,n+1
for t,_,d in eval('I(),'*q)[::-1]:L,R=d<'R',d>'L';l+=(t==s[l+1])*L-(t==s[l])*R;r+=(t==s[r])*L-(t==s[r-1])*R
print((max(0,r-l-1))) | I=input;n,q=list(map(int,I().split()));s=' %s '%I();l,r=0,n+1
for t,_,d in eval('I(),'*q)[::-1]:L=d<'R';R=1-L;l+=(t==s[l+1])*L-(t==s[l])*R;r+=(t==s[r])*L-(t==s[r-1])*R
print((max(0,r-l-1))) | p03081 |
N, x = list(map(int, input().split()))
num_list = [int(x) for x in input().split()]
count = 0
if x == 0:
print((sum(num_list)))
else:
while True:
mark = 0
for i, num in enumerate(num_list[0:-1]):
if (num_list[i] + num_list[i+1] > x):
if num_list[i+1] != 0:
num_list[i+1] = ... | N, x = list(map(int, input().split()))
num_list = [int(x) for x in input().split()]
count = 0
for i in range(N-1):
n = num_list[i] + num_list[i+1]
if n > x:
if n - num_list[i+1] > x:
count += n - x
num_list[i+1] = 0
else:
count += n - x
num_list[i+1] -= (n-x)
print(co... | p03862 |
n, x = list(map(int,input().split()))
A = list(map(int,input().split()))
sum = []
ans = 0
for i in range(n-1):
sum.append(A[i]+A[i+1])
for j in range(n-1):
if j != n-2:
while sum[j] > x:
sum[j] -= 1
sum[j+1] -= 1
ans += 1
else:
while sum[j] > ... | n, x = list(map(int,input().split()))
A = list(map(int,input().split()))
if A[0] > x:
ans = A[0] - x
A[0] -= ans
else:
ans = 0
for j in range(n):
if j != n-1:
if A[j]+A[j+1]> x:
diff = A[j+1]+A[j]-x
ans += diff
if A[j+1] - diff > 0:
... | p03862 |
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(0, N - 1):
while (a[i] + a[i + 1]) > x:
a[i + 1] -= 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):
total = a[i] + a[i + 1]
if total > x:
a[i + 1] = max(0, a[i + 1] - (total - x))
ans += (total - x)
print(ans) | p03862 |
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(1, n):
if a[i-1] + a[i] > x:
tmp = a[i]
a[i] = max(x-a[i-1], 0)
ans += tmp - a[i]
if a[i] == 0 and a[i-1] > x:
tmp = a[i-1]
a[i-1] = x
ans += tmp - a[i-1]
print(ans) |
N,x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
if A[0] > x:
ans += A[0] - x
A[0] = x
for i in range(1,N):
if A[i] + A[i-1] > x:
tmp = A[i] + A[i-1] - x
ans += tmp
A[i] -= tmp
print(ans) | p03862 |
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
s = A[i] + A[i-1]
if s > x:
y = s-x
if A[i] > y:
A[i] -= y
A[i-1] -= y
ans += y
else:
z = y - A[i]
A[i] = 0
... | N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
now = A[0]
if now > x:
ans += now - x
now = x
for i in range(1, N):
if now + A[i] > x:
y = now + A[i] - x
ans += y
A[i] = max(0, A[i] - y)
now = A[i]
print(ans)
| p03862 |
n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=0
if a[0]>x:
ans=a[0]-x
a[0]=x
for i in range(1,n):
if a[i-1]+a[i]>x:
ans+=a[i-1]+a[i]-x
a[i]=x-a[i-1]
print(ans) | n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=0
if a[0]>x:
ans+=a[0]-x
a[0]=x
for i in range(1,n):
if a[i]+a[i-1]>x:
ans+=a[i]+a[i-1]-x
a[i]-=a[i]+a[i-1]-x
print(ans) | p03862 |
N,x=list(map(int,input().split()))
S = [int(i) for i in input().split()]
pre,ans = 0,0
for i in range(N):
tmp = pre+S[i]
if tmp > x:
ans += tmp-x
S[i] -= tmp-x
pre = S[i]
print(ans) | N,x=list(map(int,input().split()))
S = list(map(int,input().split()))
pre,ans = 0,0
for i in range(N):
tmp = pre+S[i]
if tmp > x:
ans += tmp-x
S[i] -= tmp-x
pre = S[i]
print(ans) | p03862 |
import math
N, x = list(map(int, input().split()))
L = [int(x) for x in input().split()]
ans = 0
for i in range(1,N):
if L[i-1] + L[i] > x:
if L[i-1] > x:
ans += L[i-1] - x
ans += L[i]
L[i] = 0
else:
ans += L[i] + L[i-1] - x
L[i... | N, x = list(map(int, input().split()))
A = [0] + [int(x) for x in input().split()]
ans = 0
for i in range(1,N+1):
if A[i-1] + A[i] > x:
ans += A[i-1] + A[i] - x
A[i] = x - A[i-1]
print(ans)
| p03862 |
# ABC048C - Boxes and Candies
def main():
n, x = list(map(int, input().rstrip().split()))
A = list(map(int, input().rstrip().split()))
ans = 0
if A[0] > x:
ans += A[0] - x
A[0] = x
for i in range(n - 1):
dif = A[i] + A[i + 1] - x
if dif > 0:
A[i... | # ARC064C - Boxes and Candies (ABC048C)
def main():
n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = A[0] - x if A[0] > x else 0
A[0] = min(A[0], x)
for i in range(n - 1):
dif = A[i] + A[i + 1] - x
if dif > 0:
A[i + 1] -= dif
... | p03862 |
# ARC064C - Boxes and Candies (ABC048C)
def main():
n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = A[0] - x if A[0] > x else 0
A[0] = min(A[0], x)
for i in range(n - 1):
dif = A[i] + A[i + 1] - x
if dif > 0:
A[i + 1] -= dif
... | # ARC064C - Boxes and Candies (ABC048C)
def main():
n, x = list(map(int, input().rstrip().split()))
A = list(map(int, input().rstrip().split()))
# modify A[0] if >x
ans = 0 if A[0] < x else A[0] - x
A[0] = min(A[0], x)
prv = A[0]
for i in range(1, n):
dif = prv + A[i... | p03862 |
def main():
n, x, *a = list(map(int, open(0).read().split()))
a = [0] + a
ans = 0
tmp = 0
for i, j in zip(a, a[1:]):
i -= tmp
if i + j - x > 0:
c = i + j - x
ans += c
tmp = c
else:
tmp = 0
print(ans)
if _... | def main():
n, x, *a = list(map(int, open(0).read().split()))
a = [0] + a
ans = 0
tmp = 0
for i, j in zip(a, a[1:]):
i -= tmp
if (i + j - x) > 0:
c = (i + j - x)
ans += c
tmp = c
else:
tmp = 0
print(ans)
... | p03862 |
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
count=0
if(a[0]>x):
count=a[0]-x
a[0]=x
for ind,i in enumerate(a):
if(ind==len(a)-1):
break
s=i+a[ind+1]
while(s>x):
count+=1
a[ind+1]-=1
s=i+a[ind+1]
print(count)
| n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
count=0
if(a[0]>x):
count=a[0]-x
a[0]=x
for ind,i in enumerate(a):
if(ind==len(a)-1):
break
s=i+a[ind+1]
if(s>x):
count+=s-x
a[ind+1]-=s-x
#s=i+a[ind+1]
print(count)
| p03862 |
n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
count=0
if(a[0]>x):
count=a[0]-x
a[0]=x
for ind,i in enumerate(a):
if(ind==len(a)-1):
break
s=i+a[ind+1]
if(s>x):
count+=s-x
a[ind+1]-=s-x
#s=i+a[ind+1]
print(count)
| n,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
if(n==1):
print((a[0]-x))
exit()
ope=0
if(a[0]>x):
ope+=a[0]-x
a[0]=x
for i in range(n-1):
c=a[i]+a[i+1]
if(c>x):
a[i+1]-=c-x
ope+=c-x
print(ope) | p03862 |
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
if A[0] > X:
ans += A[0] - X
A[0] = X
for i in range(N-1):
if A[i] + A[i+1] > X:
ans -= X - (A[i] + A[i + 1])
A[i+1] += X - (A[i] + A[i+1])
print(ans) | n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
v=sum(a)
if k<a[0]:
a[0]=k
for i in range(n-1):
if k<a[i]+a[i+1]:
a[i+1]=k-a[i]
print((v-sum(a))) | p03862 |
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
v=sum(a)
if k<a[0]:
a[0]=k
for i in range(n-1):
if k<a[i]+a[i+1]:
a[i+1]=k-a[i]
print((v-sum(a))) | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
total=sum(a)
if m<a[0]:
a[0]=m
for i in range(1,n):
if m<a[i]+a[i-1]:
a[i]=m-a[i-1]
tot=sum(a)
print((total-tot)) | p03862 |
n,x=list(map(int,input().split()))
*a,=list(map(int,input().split()))
v=[i if i<x else x for i in a]
b=[v[i]+v[i+1]<=x for i in range(n-1)]
while not all(b):
f=True
for i in range(n-2):
if not b[i] and not b[i+1]:
v[i+1]=x-v[i]
f=False
break
if... | n,x=list(map(int,input().split()))
*a,=list(map(int,input().split()))
v=[i if i<x else x for i in a]
for i in range(n-1):
if v[i]+v[i+1]>x:
v[i+1]=x-v[i]
print((sum(a)-sum(v))) | p03862 |
import sys
# sys.stdin = open('c1.in')
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
def main():
n, x = read_int_list()
a = r... | import sys
# sys.stdin = open('c1.in')
def read_int_list():
return list(map(int, input().split()))
def read_str_list():
return input().split()
def read_int():
return int(eval(input()))
def read_str():
return eval(input())
def main():
n, x = read_int_list()
a = r... | p03862 |
def solve():
n, x = list(map(int, input().split()))
s = list(map(int, input().split()))
cnt, tmp, flg = 0, 0, False
for i in range(n - 1):
if i == 0 and s[i] > x:
cnt += s[i] - x
s[i] = x
if s[i] + s[i + 1] > x:
tmp = s[i] + s[i + 1] - x
... | def solve():
n, x = list(map(int, input().split()))
s = list(map(int, input().split()))
cnt, tmp, prv = 0, 0, 0
if s[0] > x:
cnt += s[0] - x
s[0] = x
for y in s:
if prv + y > x:
tmp = prv + y - x
cnt += tmp
prv = y - tmp
... | p03862 |
# coding: utf-8
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(N - 1): # 貪欲法で解く
while a[i] + a[i + 1] > x and a[i + 1] >= 1: # 左の組から順に、組の右側から食べていく
ans += 1
a[i + 1] -= 1
while a[i] + a[i + 1] > x: # それでも足りないなら組の左側も食べる
ans += 1
... | # coding: utf-8
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(N - 1): # 貪欲法で解く
if a[i] + a[i + 1] > x and a[i + 1] >= 1: # 左の組から順に、組の右側から食べていく
ans += min(a[i] + a[i + 1] - x, a[i + 1])
a[i + 1] -= min(a[i] + a[i + 1] - x, a[i + 1])
if a... | p03862 |
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
diff = [a[i] + a[i+1] for i in range(N-1)]
counter = 0
for i in range(N-2):
while diff[i] > x:
counter += 1
diff[i] -= 1
diff[i+1] -= 1
if diff[N-2] > x:
counter += diff[N-2] - x
print(counter) | N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a += [0]
counter = 0
for i in range(N-1):
flow = a[i] + a[i+1] - x
if flow > 0:
counter += flow
a[i+1] = max(a[i+1]-flow, 0)
print(counter)
| p03862 |
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem C
if __name__ == '__main__':
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
if a[0] > x:
count += a[0] - x
a[0] -= count
for i in range(n - 1):
summed = a[i] ... | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem C
if __name__ == '__main__':
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
if a[0] > x:
count += a[0] - x
a[0] -= count
for i in range(n - 1):
diff = a[i] + ... | p03862 |
n,x=list(map(int,input().split()));a=list(map(int,input().split()));ans=0
for i in range(n-1):
while sum(a[i:i+1+1])>x:
if a[i+1]==0:a[i]-=1
else:a[i+1]-=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):
m=a[i]+a[i+1]
if a[i]>=x:a[i+1]=0;a[i]=x
else:a[i+1]=min(x-a[i],a[i+1])
ans+=m-a[i]-a[i+1]
print(ans) | p03862 |
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
for i in a:
if i > x:
i = x
count += i - x
b = a.copy()
count1 = count
for i in range(n-1):
while a[i] + a[i+1] > x:
if a[i] > 0:
a[i] -= 1
else:
a[i+1... | n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
previous = 0
for i in a:
if i + previous > x:
excess = i + previous - x
count += excess
previous = x - previous
else: # if not exceeding x.
previous = i
print(count)
| p03862 |
import sys
n, x, *a = list(map(int, sys.stdin.read().split()))
a = [0] + a
def main():
tot = 0
for i in range(1, n + 1):
if a[i] + a[i-1] > x:
tot += a[i] + a[i-1] - x
a[i] = x - a[i-1]
print(tot)
if __name__ == '__main__':
main() | import sys
n, x, *a = list(map(int, sys.stdin.read().split()))
def main():
cnt = 0
lim = x
for c in a:
if c > lim:
cnt += c - lim
lim = x - lim
else:
lim = x - c
print(cnt)
if __name__ == '__main__':
main() | p03862 |
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
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 += 1
print(cnt) | N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
if A[i] + A[i+1] > x:
diff = A[i] + A[i+1] - x
if A[i+1]>diff:
A[i+1] -= diff
else:
A[i+1] = 0
cnt += diff
print(cnt) | p03862 |
n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, n):
if A[i-1]+A[i] <= x:
continue
eat = A[i-1]+A[i] - x
ans += eat
A[i] = max(0, A[i]-eat)
print(ans) | n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(n):
if i == 0:
if A[i] <= x:
continue
eat = A[i] - x
ans += eat
A[i] = A[i] - eat
continue
if A[i-1]+A[i] <= x:
continue
eat = A[i-1] + A... | p03862 |
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
num = len(a)
ans = 0
for i in range(num - 1):
tar = a[i] + a[i + 1]
if (tar <= x):
continue
else:
while (tar > x):
a[i + 1] -= 1
ans += 1
tar = a[i] + a[i + 1]
... | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
num = len(a)
ans = 0
for i in range(num - 1):
tar = a[i] + a[i + 1]
if (tar <= x):
continue
else:
dif = tar - x
if (a[i + 1] >= dif):
ans += dif
a[i + 1] -= dif
... | p03862 |
(N,x),a=[list(map(int,input().split()))for _ in[0]*2];r=0
for i in range(1,N):e=max(a[i]+a[i-1]-x,0);a[i]-=min(e,a[i]);r+=e
print(r) | n,x,*a=list(map(int,open(0).read().split()));r=0
for i in range(1,n):e=max(a[i]+a[i-1]-x,0);a[i]-=min(e,a[i]);r+=e
print(r) | p03862 |
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
while a[i] + a[i + 1] > x:
if a[i + 1] == 0:
ans += 1
a[i] -= 1
else:
ans += 1
a[i + 1] -= 1
print(ans) | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
if a[i] + a[i + 1] > x:
ans += a[i + 1] + a[i] - x
a[i + 1] = x - a[i]
if a[i + 1] < 0:
a[i + 1] = 0
print(ans) | p03862 |
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
while a[i] + a[i + 1] > x:
if a[i + 1] != 0:
ans += 1
a[i + 1] -= 1
else:
ans += 1
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):
if a[i] + a[i + 1] > x:
ans += a[i + 1] + a[i] - x
a[i + 1] = x - a[i]
if a[i + 1] < 0:
a[i + 1] = 0
print(ans) | p03862 |
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
delta = max(0, a[i] + a[i+1] - x)
a[i+1] -= delta
if a[i+1] < 0:
a[i] += a[i+1]
a[i+1] = 0
ans += delta
print(ans) | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 0
for i in range(n-1):
t = max(0, a[i] + a[i+1] - x)
a[i+1] -= t
if a[i+1] < 0:
a[i] += a[i+1]
a[i+1] = 0
c += t
print(c) | p03862 |
N,X=list(map(int,input().split()))
*A,=list(map(int,input().split()))
ans=0
if A[0]>X:
ans+=A[0]-X
A[0]=X
i=0
while i+1<=N-1:
if A[i]+A[i+1]>X:
ans+=A[i]+A[i+1]-X
A[i+1]=X-A[i]
i+=1
print(ans) | N,X=list(map(int,input().split()))
*A,=list(map(int,input().split()))
ans=0
if A[0]>X:
ans+=A[0]-X
A[0]=X
i=1
while i<N:
if A[i]+A[i-1]>X:
ans+=A[i]+A[i-1]-X
A[i]=X-A[i-1]
i+=1
print(ans) | p03862 |
N,X=(int(T) for T in input().split())
A=list(map(int,input().split()))
ans=0
for i in range(0,N-1):
if A[i]+A[i+1]>X:
s=A[i]+A[i+1]-X
ans=s+ans
A[i]=A[i]-max(0,A[i]-A[i+1])
A[i+1]=max(0,A[i+1]-s)
print(ans)
| N,x=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=0
for i in range(1,N):
tmp=a[i-1]+a[i]
if tmp>x:
ans+=tmp-x
if a[i]>=tmp-x:
a[i]-=tmp-x
else:
a[i]=0
print(ans)
| p03862 |
import copy
[n,x]=list(map(int,input().split()))
a=list(map(int,input().split()))
a0=copy.copy(a)
ans=0
for i in range(n-1):
while a[i]+a[i+1]>x:
a[i+1]-=1
ans+=1
print(ans) | import copy
[n,x]=list(map(int,input().split()))
a=list(map(int,input().split()))
a0=copy.copy(a)
ans=0
if a[0]+a[1]>x and a[0]>x:
ans+=a[0]-x
a[0]-=a[0]-x
if a[0]+a[1]>x:
ans+=a[1]
a[1]=0
for i in range(n-1):
if a[i]+a[i+1]>x:
ans+=a[i]+a[i+1]-x
a[i+1]-=a[i]+a[i+1]-x
print(ans) | p03862 |
n,x,*a=list(map(int,open(0).read().split()))
ans=0
if a[0]>x:
ans=a[0]-x
a[0]=x
for i in range(n-1):
while a[i+1]+a[i]>x:
a[i+1]-=1
ans+=1
print(ans) | n,x,*a=list(map(int,open(0).read().split()))
ans=0
if a[0]>x:
ans=a[0]-x
a[0]=x
for i in range(n-1):
if a[i+1]+a[i]>x:
d=a[i+1]+a[i]-x
a[i+1]-=d
ans+=d
print(ans) | p03862 |
N,x =list(map(int,input().split()))
a=list(map(int,input().split()))
cnt=0
for i in range(N-1):
if a[i]+a[i+1]>x:
while a[i+1]>0 and a[i]+a[i+1]>x:
a[i+1]-=1
cnt+=1
#端はこの操作では実現できない可能性があるので別に
if a[0]+a[1]>x:
while a[0]+a[1]>x:
a[0]-=1
cnt+=1
if a[-1]+a... | N,x =list(map(int,input().split()))
a=list(map(int,input().split()))
cnt=0
for i in range(N-1):
if a[i]+a[i+1]>x:
#マイナスになるのを防ぐ
if a[i+1]<(a[i]+a[i+1]-x):
cnt+=a[i+1]
a[i+1]=0
else:
cnt+=a[i]+a[i+1]-x
a[i+1]-=a[i]+a[i+1]-x
#端はこの操作では実... | p03862 |
N,x = list(map(int, input().split()))
alist = list(map(int,input().split()))
ans = 0
for al in range(1,N):
while (alist[al-1]+alist[al]) > x:
alist[al] -= 1
ans += 1
print(ans) | N,x = list(map(int, input().split()))
alist = list(map(int,input().split()))
ans = 0
if alist[0] > x:
ans += (alist[0] - x)
alist[0] -= (alist[0] - x)
for al in range(1,N):
if (alist[al-1]+alist[al]) > x:
ans += (alist[al-1]+alist[al]) - x
alist[al] -= (alist[al-1]+alist[al]) - ... | p03862 |
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(N-1):
if (a[i]+a[i+1]) > x and x < a[i] :
ans += a[i+1]+a[i]-x
a[i] = a[i]-(x-a[i+1])
a[i+1] = 0
elif (a[i]+a[i+1]) > x:
ans += a[i+1]+a[i]-x
... | N, x = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.insert(0, 0)
ans = 0
for i in range(N):
if A[i] + A[i+1] > x:
ans += abs(A[i+1]-(x-A[i]))
A[i+1] = x - A[i]
print(ans) | p03862 |
N, X = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(N-1):
if a[i] + a[i+1] > X:
if X - a[i] >= 0:
ans += a[i+1] - (X - a[i])
a[i+1] = (X - a[i])
else:
ans += a[i+1]
a[i+1] = 0
... | N, x = list(map(int, input().split()))
a = [int(i) for i in input().split()]
ans = 0
if a[0] > x:
ans += a[0] - x
a[0] = x
for i in range(1, N):
if a[i] + a[i - 1] > x:
ans += a[i] - (x - a[i - 1])
a[i] = x - a[i - 1]
print(ans) | p03862 |
def main():
from collections import deque
N, L = list(map(int, input().split()))
*a, = list(map(int, input().split()))
def solve(a):
dq = deque()
s = 0
ans = 0
for x in a:
if len(dq) > 1:
t = dq.popleft()
s -= t
... | def main():
from collections import deque
N, L = list(map(int, input().split()))
*a, = list(map(int, input().split()))
def solve(a):
dq = deque()
s = 0
ans = 0
for x in a:
if len(dq) > 1:
t = dq.popleft()
s -= t
... | p03862 |
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
for i in range(N-1):
if (A[i]+A[i+1]) > x:
cnt = (A[i]+A[i+1]) - x
ans += cnt
A[i+1] -= cnt
if A[i+1] < 0:
A[i+1] = 0
print(ans) | N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
limit = x
for a in A:
if limit < a:
ans += a - limit
limit = x - limit
else:
limit = x - a
print(ans) | p03862 |
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(1, n):
while a[i-1] + a[i] > x:
a[i] -= 1
ans += 1
print(ans)
| n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
if a[0] > x:
ans += a[0] - x
a[0] = x
# print(a, ans)
for i in range(1, n):
total = a[i-1] + a[i]
if total > x:
# print('yay,', total-x)
a[i] -= total - x
ans += total - x
... | p03862 |
N, X = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
cost = 0
diff = max(0, sum(A[0:2]) - X)
A[0] -= max(0, diff - A[1])
A[1] -= min(A[1], diff)
cost += diff
for i in range(2, N):
diff = max(0, A[i - 1] + A[i] - X)
A[i - 1] -= max(0, diff - A[i])
A[i] -= min(A[i], d... | N, X = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
cost = max(0, A[0] + A[1] - X)
A[1] = max(0, A[1] - cost)
for i in range(2, N):
cost += max(0, A[i - 1] + A[i] - X)
A[i] = max(0, A[i] - max(0, A[i - 1] + A[i] - X))
print(cost)
| p03862 |
N,x = list(map(int,input().split()))
a=list(map(int,input().split()))
eat=0
if a[0]>x:
eat+=a[0]-x+1
a[0]=x-1
for i in range(N-1):
while a[i]+a[i+1]>x:
a[i+1]-=1
eat+=1
print(eat) | N,x = list(map(int,input().split()))
a=list(map(int,input().split()))
eat=0
if a[0]>x:
eat+=a[0]-x
a[0]=x
if a[N-1]>x:
eat+=a[N-1]-x
a[N-1]=x
for i in range(N-1):
if a[i]+a[i+1]>x:
eat+=a[i+1]-x+a[i]
a[i+1]=x-a[i]
print(eat) | p03862 |
N,X=list(map(int,input().split()))
*A,=list(map(int,input().split()))
B=[0]*N
for i in range(N):
B[i] = A[i] if A[i]<=X else X
cnt=sum(A)-sum(B)
for i in range(N-1):
if X < B[i]+B[i+1]:
d=B[i]+B[i+1]-X
B[i+1]-=d
cnt+=d
print(cnt) | N,X=list(map(int,input().split()))
*A,=list(map(int,input().split()))
B=[a if a<=X else X for a in A]
c=sum(A)-sum(B)
for i in range(N-1):
t=B[i]+B[i+1]
if X < t:
d=t-X
B[i+1]-=d
c+=d
print(c) | p03862 |
N,x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
while a[0] > x:
a[0] -= 1
count += 1
for i in range(N-1):
while a[i] + a[i+1] > x:
a[i+1] -= 1
count += 1
print(count)
| N,x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
while a[0] > x:
count += a[0] - x
a[0] = x
for i in range(N-1):
if a[i] + a[i+1] > x:
count += a[i+1] - (x - a[i])
a[i+1] = x - a[i]
print(count)
| p03862 |
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
while a[i] + a[i+1] > x:
a[i+1]-=1
cnt+=1
print(cnt)
| N, x = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
cnt = 0
for i in range(N):
if a[i]+a[i+1]>x:
tmp = a[i]+a[i+1]-x
a[i+1] -= tmp
cnt+=tmp
print(cnt)
| p03862 |
N,x = list(map(int,input().split()))
A = list(map(int,input().split()))
ans = 0
for i in range(1,N):
y = max(A[i]+A[i-1]-x,0)
if A[i]>=y:
A[i] -= y
else:
A[i] = 0
ans += y
print(ans) | N,x = list(map(int,input().split()))
A = list(map(int,input().split()))
cnt = 0
for i in range(1,N):
if A[i]+A[i-1]>x:
d = A[i]+A[i-1]-x
if A[i]>=d:
A[i] -= d
cnt += d
else:
A[i]=0
cnt += A[i]
d -= A[i]
A[i-... | p03862 |
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
def solve(N,x,A):
ans = max(A[0]-x,0)
A[0] -= ans
for i in range(1,N):
p = max(A[i]-(x-A[i-1]),0)
A[i] -= p
ans += p
return ans
print((solve(N,x,A))) | def solve():
ans = 0
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
if A[0]>x:
ans += A[0]-x
A[0] = x
for i in range(1,N):
if A[i]+A[i-1]>x:
ans += A[i]+A[i-1]-x
A[i] = x-A[i-1]
return ans
print((solve())) | p03862 |
# coding: utf-8
n, x = list(map(int,input().split()))
A = list(map(int,input().split()))
S = sum(A)
if A[0] > x:
A[0] = x
for i in range(n-1):
s = A[i+1] + A[i]
if s > x:
A[i+1] -= s - x
print((S - sum(A))) | # coding: utf-8
n, x = list(map(int,input().split()))
A = list(map(int,input().split()))
S = sum(A)
for i in range(n-1):
s = A[i+1] + A[i]
if s > x:
if s-x > A[i+1]:
t = s-x-A[i+1]
A[i+1] = 0
A[i] -= t
else:
A[i+1] -= s - x
print((S - ... | p03862 |
# coding: utf-8
n, x = list(map(int,input().split()))
A = list(map(int,input().split()))
S = sum(A)
for i in range(n-1):
s = A[i+1] + A[i]
if s > x:
if s-x > A[i+1]:#後ろから全部引ける時
t = s-x-A[i+1]
A[i+1] = 0
A[i] -= t
else:#後ろから全部引くと負になるとき(前からも引く)
... | # coding: utf-8
n, x = list(map(int,input().split()))
A = list(map(int,input().split()))
S = sum(A)
for i in range(n-1):
s = A[i+1] + A[i]
if s > x:
if A[i+1] >= s-x:
A[i+1] -= (s-x)
else:
t = s-x-A[i+1]
A[i+1] = 0
A[i] -= t
print((S -... | p03862 |
#6問目
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
for i in range(N-1):
if(a[i] + a[i+1] > x):
while(a[i] + a[i+1] > x):
count += 1
a[i+1] -= 1
print(count) | #6問目
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
for i in range(N-1):
#まず一番前の要素がxより小さくなければならない
if(i == 0 and a[i] > x):
count += a[i] - x
a[i] = x
if(a[i] + a[i+1] > x):
count += a[i] + a[i+1] - x
a[i+1] = x - a[i]... | p03862 |
N,x=list(map(int,input().split()))
A=list(map(int,input().split()))
A2=A[::-1]
ANS=0
for i in range(1,N):
if A[i]+A[i-1]>x:
ANS+=(A[i]+A[i-1]-x)
if A[i]>=A[i]+A[i-1]-x:
A[i]-=(A[i]+A[i-1]-x)
else:
A[i]=0
ANS2=0
for i in range(1,N):
if A2[i]+A2... | N,x=list(map(int,input().split()))
A=list(map(int,input().split()))
ANS=0
for i in range(1,N):
if A[i]+A[i-1]>x:
ANS+=(A[i]+A[i-1]-x)
if A[i]>=A[i]+A[i-1]-x:
A[i]-=(A[i]+A[i-1]-x)
else:
A[i]=0
print(ANS)
| p03862 |
N,x= list(map(int,input().split()))
array = list(map(int,input().split()))
result=0
for i in range(0,N-1):
#i と i+1 が閾値以下じゃなかったら
while array[i] + array[i+1] > x:
if array[i+1]!=0:
array[i+1]-=1
else:
array[i]-=1
result+=1
print(result) | N,x= list(map(int,input().split()))
array = list(map(int,input().split()))
array2=array.copy()
result=0
#TLE pattern
# for i in range(0,N-1):
# #i と i+1 が閾値以下じゃなかったら
# while array[i] + array[i+1] > x:
# if array[i+1]!=0:
# array[i+1]-=1
# else:
# array[i]-=1
... | p03862 |
n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
b=a[0]
ans=0
for i in range(1,n):
if b>x:
ans+=b-x
b=x
if a[i]+b>x:
ans+=b-x+a[i]
a[i]=x-b
b=a[i]
print(ans) | n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=max(a[0]-x,0)
a[0]-=ans
for i in range(n-1):
if a[i]+a[i+1]>x:
ans+=a[i+1]+a[i]-x
a[i+1]=x-a[i]
print(ans) | p03862 |
# -*- coding: utf-8
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
if a[0] > x:
count += a[0] - x
a[0] = x
for i in range(len(a) - 1):
while a[i] + a[i + 1] > x:
a[i + 1] -= 1
count += 1
print(count)
| # -*- coding: utf-8
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = max(0, a[0] - x)
a[0] = min(a[0], x)
for i in range(len(a) - 1):
if a[i] + a[i + 1] > x:
tmp_num = max(0, a[i] + a[i + 1] - x)
count += tmp_num
a[i + 1] -= tmp_num
print(cou... | p03862 |
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): ret... | import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): ret... | p03862 |
N,x =list(map(int,input().split()))
a=[int(i) for i in input().split()]
ans=0
if a[0] >x:
ans += (a[0]-x)
a[0] -= (a[0]-x)
for i in range(N-1):
if a[i]+a[i+1] >x:
ans += ((a[i]+a[i+1])-x)
a[i+1] -= ((a[i]+a[i+1])-x)
else: continue
print(ans) | N,x=list(map(int,input().split()))
A=list(map(int,input().split())) +[0]
ans =0
for i in range(N):
eated =max(0,A[i]+A[i-1]-x)
ans +=eated
A[i]-=eated
print(ans)
| p03862 |
N,X,*A = list(map(int,open(0).read().split()))
A+=[0]
s = 0
for n in range(N):
d=max(0,A[n]+A[n-1]-X)
s+=d
A[n]-=d
print(s) | N,x = list(map(int,input().split()))
A = list(map(int,input().split()))
pre = 0
ans = 0
for a in A:
eat = max(0,pre+a-x)
pre = a - eat
ans+= eat
print(ans) | p03862 |
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
for i in range(N-1):
while a[i]+a[i+1]>x:
if a[i]>a[i+1]:
a[i] -= 1
count += 1
else:
a[i+1] -= 1
count += 1
print(count)
| N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
for i in range(N-1):
while a[i]+a[i+1] > x:
if a[i]>x:
count += a[i]-x
a[i] = x
else:
count += a[i+1] - (x-a[i])
a[i+1] = x - a[i]
print(count) | p03862 |
N,x,*A=list(map(int,open(0).read().split()));s=sum(A);A=[min(x,a)for a in A]
for i in range(N-1):A[i+1]-=max(0,A[i]+A[i+1]-x)
print((s-sum(A))) | N,x,*A=list(map(int,open(0).read().split()));s=sum(A);A+=0,
for i in range(N):A[i]-=max(0,A[i]+A[i-1]-x)
print((s-sum(A))) | p03862 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.