Problem:


﻿Score : 400 points

Problem Statement

In the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called AtCoder Express.

In the plan developed by the president Takahashi, the trains will run as follows:

A train will run for (t_1 + t_2 + t_3 + ... + t_N) seconds.

In the first t_1 seconds, a train must run at a speed of at most v_1 m/s (meters per second). Similarly, in the subsequent t_2 seconds, a train must run at a speed of at most v_2 m/s, and so on.

According to the specifications of the trains, the acceleration of a train must be always within ±1m/s^2. Additionally, a train must stop at the beginning and the end of the run.

Find the maximum possible distance that a train can cover in the run.

Constraints

1 \leq N \leq 100

1 \leq t_i \leq 200

1 \leq v_i \leq 100

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
t_1 t_2 t_3 … t_N
v_1 v_2 v_3 … v_N

Output

Print the maximum possible that a train can cover in the run.

Output is considered correct if its absolute difference from the judge's output is at most 10^{-3}.

Sample Input 1

1
100
30

Sample Output 1

2100.000000000000000

The maximum distance is achieved when a train runs as follows:

In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.

In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.

In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.

The total distance covered is 450 + 1200 + 450 = 2100 meters.

Sample Input 2

2
60 50
34 38

Sample Output 2

2632.000000000000000

The maximum distance is achieved when a train runs as follows:

In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.

In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.

In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.

In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.

In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.

The total distance covered is 578 + 884 + 144 + 304 + 722 = 2632 meters.

Sample Input 3

3
12 14 2
6 2 7

Sample Output 3

76.000000000000000

The maximum distance is achieved when a train runs as follows:

In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.

In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.

In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.

In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.

In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.

The total distance covered is 18 + 12 + 16 + 28 + 2 = 76 meters.

Sample Input 4

1
9
10

Sample Output 4

20.250000000000000000

The maximum distance is achieved when a train runs as follows:

In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.

In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.

The total distance covered is 10.125 + 10.125 = 20.25 meters.

Sample Input 5

10
64 55 27 35 76 119 7 18 49 100
29 19 31 39 27 48 41 87 55 70

Sample Output 5

20291.000000000000



Sample input:
1
100
30


Sample output:
2100.000000000000000

Submission status: Wrong Answer

Solution code:
def getSpeedChanges(sStart, tStart, sEnd, tEnd, sMax):
    tresult = []
    vresult = []
    
    decelPoint = ((tEnd+sEnd) + (tStart-sStart))/2
    decel = ((tEnd+sEnd) - (tStart-sStart))/2

    sMaxPoint = tStart + (sMax-sStart)
    decelFromMax = tEnd - (sMax-sEnd)
    
    if sMaxPoint < decelPoint:
        tresult += [sMaxPoint]
        vresult += [sMax]
        if sEnd >= sMax:
            tresult += [tEnd]
            vresult += [sMax]
        else:
            tresult += [decelFromMax, tEnd]
            vresult += [sMax, sEnd]
    else:
        tresult += [decelPoint, tEnd]
        vresult += [decel, sEnd]

    return tresult, vresult

def getDistance(t,v):
    result = 0
    for i in range(1,len(t)):
        result += abs((t[i] - t[i-1]) * (v[i]-v[i-1])) / 2
        result += (t[i] - t[i-1]) * min(v[i],v[i-1])

    return result

n = int(input())
t = [int(x) for x in input().split()]
v = [int(x) for x in input().split()] + [0]
for i in range(1,n):
    t[i] = t[i]+t[i-1]

tresult = [0]
vresult = [0]

for i in range(n):
    trestemp, vrestemp = getSpeedChanges(vresult[-1], tresult[-1], v[i+1], t[i], v[i])
    tresult+=trestemp
    vresult+=vrestemp

print(getDistance(tresult,vresult))

Submission status: Wrong Answer

Solution code:
def getSpeedChanges(sStart, tStart, sEnd, tEnd, sMax):
    tresult = []
    vresult = []
    
    decelPoint = ((tEnd+sEnd) + (tStart-sStart))/2
    decel = ((tEnd+sEnd) - (tStart-sStart))/2

    sMaxPoint = tStart + (sMax-sStart)
    decelFromMax = tEnd - (sMax-sEnd)
    #case 1: sEnd < sMax
    if sEnd<sMax:
        #case 1.1: sMax is reached before needing to decel
        if (decelPoint > sMaxPoint):
            tresult.append(sMaxPoint)
            vresult.append(sMax)
            
            tresult.append(decelFromMax)
            vresult.append(sMax)

            tresult.append(tEnd)
            vresult.append(sEnd)
        #case 1.2: sMax is not reached before needing to decel
        else:
            tresult.append( decelPoint )
            vresult.append( decel )
            
            tresult.append(tEnd)
            vresult.append(sEnd)
    
    #case 2: sEnd >= sMax
    else:
        tresult.append(sMaxPoint)
        vresult.append(sMax)
        
        tresult.append(tEnd)
        vresult.append(sMax)

    return tresult, vresult

def getDistance(t,v):
    result = 0
    for i in range(1,len(t)):
        result += abs((t[i] - t[i-1]) * (v[i]-v[i-1])) / 2
        result += (t[i] - t[i-1]) * min(v[i],v[i-1])

    return result

n = int(input())
t = [int(x) for x in input().split()]
v = [int(x) for x in input().split()] + [0]
for i in range(1,n):
    t[i] = t[i]+t[i-1]

tresult = [0]
vresult = [0]

for i in range(n):
    trestemp, vrestemp = getSpeedChanges(vresult[-1], tresult[-1], v[i+1], t[i], v[i])
    tresult+=trestemp
    vresult+=vrestemp

print(getDistance(tresult,vresult))

Submission status: Wrong Answer

Solution code:
def getSpeedChanges(sStart, tStart, sEnd, tEnd, sMax):
    #case 1: sEnd < sMax
    tresult = []
    vresult = []
    if sEnd<sMax:
        #case 1.1: sMax is reached before needing to decel
        if ((tEnd+sEnd) + (tStart-sStart))/2 > tStart + (sMax-sStart):
            tresult.append(tStart+(sMax-sStart))
            vresult.append(sMax)
            
            tresult.append(tEnd - (sMax-sEnd))
            vresult.append(sMax)

            tresult.append(tEnd)
            vresult.append(sEnd)
        #case 1.2: sMax is not reached before needing to decel
        else:
            tresult.append( ((tEnd+sEnd)+(tStart-sStart))/2 )
            vresult.append( ((tEnd+sEnd)-(tStart-sStart))/2  )
            
            tresult.append(tEnd)
            vresult.append(sEnd)
    
    #case 2: sEnd >= sMax
    else:
        tresult.append(tStart+(sMax-sStart))
        vresult.append(sMax)
        
        tresult.append(tEnd)
        vresult.append(sMax)

    return tresult, vresult

def getDistance(t,v):
    result = 0
    for i in range(1,len(t)):
        result += abs((t[i] - t[i-1]) * (v[i]-v[i-1])) / 2 + (t[i] - t[i-1]) * min(v[i],v[i-1])
    return result

n = int(input())
t = [int(x) for x in input().split()]
v = [int(x) for x in input().split()] + [0]
for i in range(1,n):
    t[i] = t[i]+t[i-1]

tresult = [0]
vresult = [0]

for i in range(n):
    trestemp, vrestemp = getSpeedChanges(vresult[-1], tresult[-1], v[i+1], t[i], v[i])
    tresult+=trestemp
    vresult+=vrestemp

print(getDistance(tresult,vresult))

Submission status: Wrong Answer

Solution code:
N=int(input())
T=list(map(int,input().split()))
V=list(map(int,input().split()))
V.append(0)

for i in range(N-1,-1,-1):
  v=V[i+1]
  t=T[i]
  V[i]=min(V[i],v+t)
  
v=0
ans=0
for i in range(N):
  t_p=T[i]
  v_p=V[i]
  v_a=V[i+1]
  
  if v_p<=v_a:
    ans+=max(t_p-(v_p-v),0)*v_p+min(t_p,v_p-v)*(v+v_p)/2
    v=min(v_p,v+t_p)
  else:
    if t_p>=(v_p-v)+(v_p-v_a):
      ans+=(v_p-v_a)*(v_p+v_a)/2 + (v_p-v)*(v+v_p)/2 + v_p*(t_p-(v_p-v)-(v_p-v_a))
      v=v_a
    else:
      vx=(t_p+v+v_a)/2
      ans+=(vx+v)*(vx-v)/2+(vx+v_a)*(vx-v_a)/2
      v=v_a
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=list(map(int,input().split()))
V=list(map(int,input().split()))
V.append(0)

for i in range(N):
  v=V[i+1]
  t=T[i]
  V[i]=min(V[i],v+t)

v=0
ans=0
for i in range(N):
  t_p=T[i]
  v_p=V[i]
  v_a=V[i+1]

  if v_p<=v_a:
    ans+=max(t_p-(v_p-v),0)*v_p+min(t_p,v_p-v)*(v+v_p)/2
    v=min(v_p,v+t_p)
  else:
    if t_p>=(v_p-v)+(v_p-v_a):
      ans+=(v_p-v_a)*(v_p+v_a)/2 + (v_p-v)*(v+v_p)/2 + v_p*(t_p-(v_p-v)-(v_p-v_a))
      v=v_a
    else:
      vx=(t_p+v+v_a)/2
      ans+=(vx+v)*(vx-v)/2+(vx+v_a)*(vx-v_a)/2
      v=v_a
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=list(map(int,input().split()))
V=list(map(int,input().split()))
V.append(0)

for i in range(N):
  v=V[i+1]
  t=T[i]
  V[i]=min(V[i],v+t)

v=0
ans=0
for i in range(N):
  t_p=T[i]
  v_p=V[i]
  v_a=V[i+1]
  

  if v_p<=v_a:
    ans+=max(t_p-(v_p-v),0)*v_p+min(t_p,v_p-v)*(v+v_p)/2
    v=v_p
  else:
    if t_p>=(v_p-v)+(v_p-v_a):
      ans+=(v_p-v_a)*(v_p+v_a)/2 + (v_p-v)*(v+v_p)/2 + v_p*(t_p-(v_p-v)-(v_p-v_a))
      v=v_a
    else:
      vx=(t_p+v+v_a)/2
      ans+=(vx+v)*(vx-v)/2+(vx+v_a)*(vx-v_a)/2
      v=v_a
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=list(map(int,input().split()))
V=list(map(int,input().split()))
V.append(0)

for i in range(N):
  v=V[i+1]
  t=T[i]
  V[i]=min(V[i],v+t)

v=0
ans=0
for i in range(N):
  t_p=T[i]
  v_p=V[i]
  v_a=V[i+1]
  
  if v_p==v_a:
    ans+=t_p*v_p
    v=v_p
  elif v_p<v_a:
    ans+=max(t_p-(v_p-v),0)*v_p+min(t_p,v_p-v)*(v+v_p)/2
    v=v_p
  else:
    if t_p>=(v_p-v)+(v_p-v_a):
      ans+=(v_p-v_a)*(v_p+v_a)/2 + (v_p-v)*(v+v_p)/2 + v_p*(t_p-(v_p-v)-(v_p-v_a))
      v=v_a
    else:
      vx=(t_p+v+v_a)/2
      ans+=(vx+v)*(vx-v)/2+(vx+v_a)*(vx-v_a)/2
      v=v_a
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0]+ list(map(int,input().split()))
v = [0] + list(map(int,input().split()))

T = sum(t) 

limit=[0]*(2*T+1)
sp_forward=[0]*(2*T+1)
sp_backward=[0]*(2*T+1)

j = 1
tmp = 0
for i in range(1,2*T+1):
    limit[i] = v[j]
    tmp += 1
    if tmp == 2*t[j]:
        if j < N-1 and v[j+1] < v[j]:
            limit[i] = v[j+1]
        j+=1
        tmp = 0

for i in range(1,2*T+1):
    sp_forward[i] = min(sp_forward[i-1]+0.5, limit[i])

for i in reversed(range(0,2*T)):
    sp_backward[i] = min(sp_backward[i+1]+0.5, limit[i])

cnt = 0

for i in range(1,2*T+1):
    cnt += (min(sp_forward[i-1],sp_backward[i-1]) + min(sp_forward[i],sp_backward[i])) * 0.25
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0]+ list(map(int,input().split()))
v = [0] + list(map(int,input().split()))

T = sum(t) 

limit=[0]*(2*T+1)
sp_forward=[0]*(2*T+1)
sp_backward=[0]*(2*T+1)

j = 1
tmp = 0
for i in range(1,2*T+1):
    limit[i] = v[j]
    tmp += 0.5
    if int(tmp) == t[j]:
        if j < N-1 and v[j+1] < v[j]:
            limit[i] = v[j+1]
        j+=1
        tmp = 0

for i in range(1,2*T+1):
    sp_forward[i] = min(sp_forward[i-1]+0.5, limit[i])

for i in reversed(range(0,2*T)):
    sp_backward[i] = min(sp_backward[i+1]+0.5, limit[i])

cnt = 0

for i in range(1,2*T+1):
    cnt += (min(sp_forward[i-1],sp_backward[i-1]) + min(sp_forward[i],sp_backward[i])) * 0.25
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0]+ list(map(int,input().split()))
v = [0] + list(map(int,input().split()))

T = sum(t) 

limit=[0]*(T+1)
sp_forward=[0]*(T+1)
sp_backward=[0]*(T+1)

j = 1
tmp = 0
for i in range(1,T+1):
    limit[i] = v[j]
    tmp += 1
    if tmp == t[j]:
        if j < N-1 and v[j+1] < v[j]:
            limit[i] = v[j+1]
        j+=1
        tmp = 0

    
for i in range(1,T+1):
    sp_forward[i] = min(sp_forward[i-1]+1, limit[i])

for i in reversed(range(0,T)):
    sp_backward[i] = min(sp_backward[i+1]+1, limit[i])

cnt = 0

for i in range(1,T+1):
    if sp_forward[i-1] == sp_backward[i] and (sp_forward[i-1] < sp_forward[i] or sp_backward[i-1] > sp_backward[i]):
        cnt += sp_backward[i] + 0.25
    elif sp_forward[i-1] == sp_backward[i]:
        cnt+=sp_backward[i]
    else:
        cnt += min(sp_forward[i-1], sp_backward[i]) + 0.5
    
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0]+ list(map(int,input().split()))
v = [0] + list(map(int,input().split()))

T = sum(t) 

limit=[0]*(T+1)
sp_forward=[0]*(T+1)
sp_backward=[0]*(T+1)

j = 1
tmp = 0
for i in range(1,T+1):
    limit[i] = v[j]
    tmp += 1
    if tmp == t[j]:
        if j < N-1 and v[j+1] < v[j]:
            limit[i] = v[j+1]
        j+=1
        tmp = 0

    
for i in range(1,T+1):
    sp_forward[i] = min(sp_forward[i-1]+1, limit[i])

for i in reversed(range(0,T)):
    sp_backward[i] = min(sp_backward[i+1]+1, limit[i])

cnt = 0

for i in range(1,T+1):
    if sp_forward[i-1] == sp_backward[i] and sp_forward[i-1] == sp_forward[i]:
        cnt+=sp_backward[i]
    elif sp_forward[i-1] == sp_backward[i] and sp_forward[i-1] < sp_forward[i]:
        cnt += sp_backward[i] + 0.25
    else:
        cnt += min(sp_forward[i-1], sp_backward[i]) + 0.5
    
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0]+ list(map(int,input().split()))
v = [0] + list(map(int,input().split()))

T = sum(t) 

limit=[0]*(T+1)
sp_forward=[0]*(T+1)
sp_backward=[0]*(T+1)

j = 1
tmp = 0
for i in range(1,T+1):
    limit[i] = v[j]
    tmp += 1
    if tmp == t[j]:
        if j < N-1 and v[j+1] < v[j]:
            limit[i] = v[j+1]
        j+=1
        tmp = 0

    
for i in range(1,T+1):
    sp_forward[i] = min(sp_forward[i-1]+1, limit[i])

for i in reversed(range(0,T)):
    sp_backward[i] = min(sp_backward[i+1]+1, limit[i])

cnt = 0

for i in range(1,T+1):
    if sp_forward[i-1] == sp_backward[i] and sp_backward[i] == limit[i]:
        cnt+=sp_backward[i]
    elif sp_forward[i-1] == sp_backward[i] and sp_backward[i] < limit[i]:
        cnt += sp_backward[i] + 0.25
    else:
        cnt += min(sp_forward[i-1], sp_backward[i]) + 0.5
    
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0]+ list(map(int,input().split()))
v = [0] + list(map(int,input().split()))

T = sum(t) 

limit=[0]*(T+1)
sp_forward=[0]*(T+1)
sp_backward=[0]*(T+1)

j = 1
tmp = 0
for i in range(1,T+1):
    limit[i] = v[j]
    tmp += 1
    if tmp == t[j]:
        if j < N-1 and v[j+1] < v[j]:
            limit[i] = v[j+1]
        j+=1
        tmp = 0

    
for i in range(1,T+1):
    sp_forward[i] = min(sp_forward[i-1]+1, limit[i])

for i in reversed(range(0,T)):
    sp_backward[i] = min(sp_backward[i+1]+1, limit[i])

print(sp_forward)
print(sp_backward)
cnt = 0

for i in range(1,T+1):
    if sp_forward[i-1] == sp_backward[i] and sp_backward[i] == limit[i]:
        cnt+=sp_backward[i]
    elif sp_forward[i-1] == sp_backward[i] and sp_backward[i] < limit[i]:
        cnt += sp_backward[i] + 0.25
    else:
        cnt += min(sp_forward[i-1], sp_backward[i]) + 0.5
    
    
print(cnt)

Submission status: Wrong Answer

Solution code:
INF=1<<30
N = int(input())
t = [int(_) for _ in input().split()]
st=[0]*(N+1)
for i in range(N):
    st[i+1]=t[i]+st[i]
T=st[N]
st.append(T)
v = [int(_) for _ in input().split()]
v.insert(0,0)
v.append(0)
l =[0]

now=0.5
ind =1

for i in range(0,2*T-1):
    v1=INF
    v2=INF
    for j in range(ind):
        v1=min(v1,v[j]+now-st[j])
    for j in range(ind+1,N+2):
        v2=min(v2,v[j]-now+st[j])
    l.append(min(v[ind],v1,v2))
    now+=0.5
    if now>=st[ind]:
        ind+=1

l.append(0)
res=0

for i in range(2*T+1):
  res+=l[i]/2

print(res)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()

for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        break
    else:
        s = -1
        e = -1
#if s == -1:
#    print(ans)
#else:
ans = S.replace('?', 'a')
ans = ans[:s] + T + ans[e:]
print(ans)

Submission status: Wrong Answer

Solution code:
def S(x,y,i):
    if x<=y:
        if T[i]>=2*V[i]-x-y:
            return V[i]*T[i]-(V[i]-x)**2/2-(V[i]-y)**2/2
        elif T[i]<=y-x:
            return x*T[i]+T[i]**2/2
        else:
            return x*T[i]+(y-x)*T[i]-(y-x)**2/2+(T[i]-y+x)**2/4
    else:
        if T[i]>=2*V[i]-x-y:
            return V[i]*T[i]-(V[i]-x)**2/2-(V[i]-y)**2/2
        elif T[i]<=x-y:
            return y*T[i]+T[i]**2/2
        else:
            return y*T[i]+(y-x)*T[i]-(y-x)**2/2+(T[i]-x+y)**2/4
N = int(input())
T = list(map(int,input().split()))
T.insert(0,0)
V = list(map(int,input().split()))
V.insert(0,0)
X = []
for i in range(1,N+1):
    X.append(min(V[i-1],V[i],T[i]))
X.append(0)
cnt = 0
for i in range(N):
    cnt += S(X[i],X[i+1],i+1)
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
tlist = list(map(int, input().split()))
vlist = list(map(int, input().split()))
vlist.append(0)
speed = 0
x = 0
for i in range(N):
    ti = tlist[i]
    vi = vlist[i]
    vj = vlist[i+1]
    if vi <= vj:
        if vi-speed <= ti:
            x += ti*vi - ((vi-speed)**2)/2
            speed = vi
        else:
            x += ti*(2*speed+ti)/2
            speed += ti
    else:
        if speed+ti <= vj:
            x += ti*(2*speed+ti)/2
            speed += ti
        elif 2*vi-speed-vj <= ti:
            x += ti*vi - ((vi-speed)**2)/2 - ((vi-vj)**2)/2
            speed = vj
        else:
            a = (ti+vj-speed)/2
            x += a*(2*speed+a)/2 + (ti-a)*(2*vj+ti-a)/2
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))
T = [0]*(N+1)
for i in range(N):
    T[i+1] = T[i]+t[i]
def f(i, t):
    if T[i]<=t<=T[i+1]:
        return v[i]
    if t<T[i]:
        return v[i]+(t-T[i])
    else:
        return v[i]+(T[i+1]-t)
limit = [0]*(T[-1]*2+1)
for t in range(1, T[-1]*2+1):
    limit[t] = min(min(f(i, t/2) for i in range(N)), t/2, T[-1]-t/2)
print(sum(limit)/2)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))

tmax = sum(T)
Vmax = max(V)
dp = [[-1 * float('inf') for _ in range(Vmax + 1)] for _ in range(tmax)]
dp[0][0] = 0
i = 0
j = 0
vmax = V[0]
for t in range(1, tmax):
    i += 1
    if i == T[j] + 1:
        i = 1
        j += 1
        vmax = V[j]
    for v in range(1, vmax + 1):
        acc = dp[t - 1][v - 1] + v - 0.5 if v != 0 else 0.5
        if v < vmax:
            same = dp[t - 1][v] + v + 0.25
            bra = dp[t - 1][v + 1] + v + 0.5
        else:
            same = dp[t - 1][v] + v
            bra = -float('inf')
        dp[t][v] = max(acc, same, bra)

print(dp[-1][1] + 0.5)

Submission status: Wrong Answer

Solution code:

N = int(input())

t = list(map(int,input().split()))
v = list(map(int,input().split()))

alltime = sum(t)
maxslis = []
rmaxslis = []



spd = 0
ans = 0

for i in range(N):

    for j in range(t[i]):
        maxslis.append(v[i])
        rmaxslis.append(v[i])


maxslis.reverse()


for i in range(alltime):

    if i == 0:
        able = 1
        maxslis[i] = 0

    elif able < maxslis[i]:
        maxslis[i] = able
        able += 1

    else:
        able = maxslis[i]

maxslis.reverse()
maxslis.append(0)

#print (maxslis)
dtflag = False

for i in range(alltime+1):

    #print (i+1,maxslis[i],spd)

    if spd < maxslis[i]:

        ans += spd + 0.5
        spd += 1
        if spd != maxslis[i]:
            dtflag = True

    elif spd == maxslis[i]:

        if dtflag and rmaxslis[i] != maxslis[i]:
            ans += 0.25
            #print (i+1)
        ans += spd
        dtflag = False

    else:
        ans += spd - 0.5
        spd -= 1
        dtflag = False

print (ans)

Submission status: Wrong Answer

Solution code:

N = int(input())

t = list(map(int,input().split()))
v = list(map(int,input().split()))

alltime = sum(t)
maxslis = []
rmaxslis = []



spd = 0
ans = 0

for i in range(N):

    for j in range(t[i]):
        maxslis.append(v[i])
        rmaxslis.append(v[i])


maxslis.reverse()


for i in range(alltime):

    if i == 0:
        able = 1
        maxslis[i] = 0

    elif able < maxslis[i]:
        maxslis[i] = able
        able += 1

    else:
        able = maxslis[i]

maxslis.reverse()
maxslis.append(0)

#print (maxslis)
dtflag = False

for i in range(alltime+1):

    #print (i+1,maxslis[i],spd)

    if spd < maxslis[i]:

        ans += spd + 0.5
        spd += 1
        if spd != rmaxslis[i]:
            dtflag = True

    elif spd == maxslis[i]:

        if dtflag and rmaxslis[i] != maxslis[i]:
            ans += 0.25
            #print (i+1)
        ans += spd
        dtflag = False

    else:
        ans += spd - 0.5
        spd -= 1
        dtflag = False

print (ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]

for i in range(1, N) :
    t[i] += t[i-1]
    
# print(t)
l = [t_ + v_ for t_, v_ in zip(t, v[1:]+[0])]
for i in range(N-2, -1, -1) :
    l[i] = min(l[i], l[i+1])
# print(l)
# print(v)
    
cur_v, cur_t = 0, 0
ret = 0
for i in range(N) :
    # print(v[i], l[i], cur_v, cur_t)
    t1 = v[i] - cur_v + cur_t
    t2 = l[i] - v[i]
    # print(t1, t2)
    if t1 <= t2 :
        ret += (t1 - cur_t) * (cur_v + v[i]) / 2
        if t2 <= t[i] :
            ret += (t2 - t1) * v[i]
            ret += (t[i] - t2) * (v[i] + l[i] - t[i]) / 2
            cur_v = l[i] - t[i]
            cur_t = t[i]
        else :
            ret += (t[i] - t1) * v[i]
            cur_v = v[i]
            cur_t = t[i]
    
    else :
        t3 = (l[i] + cur_t - cur_v) / 2
        ret += (t3 - cur_t) * (2 * cur_v + t3 - cur_t) / 2
        ret += (t[i] - t3) * (2 * (cur_v + t3 - cur_t) - (t[i] - t3)) / 2
        cur_v = l[i] - t[i]
        cur_t = t[i]
    # print(ret)
    # print()
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split())) 
operations = T[:]
v_limits = V[:]
operations.append(0)
v_limits.append(0)

v = 0
cnt = 0
ans = 0
for i in range(N):
    t = 0
    for _ in range(operations[i]*2):
        pre_v = v
        t += 0.5
        if v_limits[i+1] < v:
            limit = min(v_limits[i], v_limits[i+1]+(operations[i]-t))
        else:
            limit = v_limits[i]
        if limit > v:
            v += 0.5
        elif limit == v:
            pass
        elif limit < v:
            v -= 0.5
        #print(t, limit, v)
        ans += (v+pre_v)*0.5/2

        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split())) 

operations = T[:]
v_limits = V[:]
operations.append(0)
v_limits.append(0)

v = 0
cnt = 0
ans = 0
for i in range(N):
    t = 0
    for _ in range(operations[i]*2):
        pre_v = v
        t += 0.5
        limit = min(v_limits[i], v_limits[i+1]+(operations[i]-t))
        if limit > v:
            v += 0.5
        elif limit == v:
            pass
        elif limit < v:
            v -= 0.5
        #print(t, limit, v)
        ans += (v+pre_v)*0.5/2

        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split())) 

operations = T[:]
v_limits = V[:]
operations.append(0)
v_limits.append(0)

v = 0
cnt = 0
ans = 0
for i in range(N):
    t = 0
    for _ in range(operations[i]*2):
        t += 0.5
        limit = min(v_limits[i], v_limits[i+1]+(operations[i]-t))
        if limit > v:
            v += 0.5
        elif limit == v:
            pass
        elif limit < v:
            v -= 0.5
        #print(t, limit, v)
        ans += v/2

        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split())) 

operations = T[:]
v_limits = V[:]
operations.append(0)
v_limits.append(0)

v = 0
cnt = 0
ans = 0
for i in range(N):
    for t in range(operations[i]*2):
        t = t / 2
        rest_t = operations[i]-t
    
        if v < v_limits[i]:
            if v >= v_limits[i+1] and rest_t == v-v_limits[i+1]:
                v -= 0.5
                ans += (v+0.5+v)*0.5/2
            else:
                if v == v_limits[i]:
                    ans += (v+v)*0.5/2
                else:
                    v += 0.5
                    ans += (v-0.5+v)*0.5/2
        else:
            if v >= v_limits[i+1] and rest_t == v-v_limits[i+1]:
                v -= 0.5
                ans += (v+0.5+v)*0.5/2
            else:
                ans += (v+v)*0.5/2
        cnt += 1
        #print(cnt, v)
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split())) 

operations = T[:]
v_limits = V[:]
operations.append(0)
v_limits.append(0)

v = 0
cnt = 0
ans = 0
for i in range(N):
    for t in range(operations[i]*2):
        t = t / 2
        rest_t = operations[i]-t
    
        if v < v_limits[i]:
            if v > v_limits[i+1] and rest_t == v-v_limits[i+1]:
                v -= 0.5
                ans += (v+0.5+v)*0.5/2
            else:
                if v == v_limits[i]:
                    ans += (v+v)*0.5/2
                else:
                    v += 0.5
                    ans += (v-0.5+v)*0.5/2
        else:
            if v > v_limits[i+1] and rest_t == v-v_limits[i+1]:
                v -= 0.5
                ans += (v+0.5+v)*0.5/2
            else:
                ans += (v+v)*0.5/2
        cnt += 1
        #print(cnt, v)
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split())) 

operations = T[:]
v_limits = V[:]
operations.append(0)
v_limits.append(0)

v = 0
cnt = 0
ans = 0
for i in range(N):
    for t in range(operations[i]*2):
        t = t / 2
        rest_t = operations[i]-t
    
        if v <= v_limits[i]:
            if v > v_limits[i+1] and rest_t == v-v_limits[i+1]:
                v -= 0.5
                ans += (v+0.5+v)*0.5/2
            else:
                if v == v_limits[i]:
                    ans += (v+v)*0.5/2
                else:
                    v += 0.5
                    ans += (v-0.5+v)*0.5/2
        else:
            if v > v_limits[i+1] and rest_t == v-v_limits[i+1]:
                v -= 0.5
                ans += (v+0.5+v)*0.5/2
            else:
                ans += (v+v)*0.5/2
        cnt += 1
        #print(cnt, v)
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split())) 

operations = T[:]
v_limits = V[:]
operations.append(0)
v_limits.append(0)

v = 0
cnt = 0
ans = 0
for i in range(N):
    for t in range(operations[i]*2):
        t = t / 2
        rest_t = operations[i]-t
    
        if v <= v_limits[i]:
            if v > v_limits[i+1] and rest_t == v-v_limits[i+1]:
                v -= 0.5
            else:
                if v == v_limits[i]:
                    pass
                else:
                    v += 0.5
        else:
            if v > v_limits[i+1] and rest_t == v-v_limits[i+1]:
                v -= 0.5
            else:
                pass
        cnt += 1
        #print(cnt, v)
        ans += v/2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
time = list(map(int, input().split())) + [0]
vels = list(map(int, input().split())) + [0]
for i in range(n)[::-1]:
    if vels[i+1] < vels[i]:
        vels[i] = min(vels[i+1] + time[i], vels[i])

ans = 0
vnow = 0
for i in range(n):
    # print(i, vnow)
    if vels[i] <= vels[i+1]:
        acc_time =  min(vels[i] - vnow, time[i])
        ans += acc_time**2 / 2 + vnow * acc_time
        # print(ans, vnow)
        vnow = vnow + acc_time
        ans += (time[i]-acc_time) * vnow
        # print(ans, vnow, acc_time)
    else:
        deacc_time = abs(vnow - vels[i+1])
        res_time = time[i] - deacc_time
        # up and down
        tmp = 0
        if vnow < vels[i+1]:
            tmp = deacc_time
        acc_time =  min((vels[i] - vnow - tmp) * 2, res_time) / 2
        ans += (acc_time**2 / 2 + (vnow + tmp) * acc_time)
        ans += (res_time-acc_time * 2) * ((vnow+tmp) + acc_time)
        ans += (-acc_time**2 / 2 + ((vnow+tmp) + acc_time) * acc_time)
        # down
        pm = 1
        if vnow > vels[i+1]:
            pm = -1
            tmp = deacc_time
        ans += pm * deacc_time**2 / 2 + (vnow) * deacc_time
        vnow = vnow + deacc_time * pm
        # print(ans, vnow, acc_time, res_time, deacc_time)
    # print(ans)
# print(vels)
print('{:.6f}'.format(ans))

Submission status: Wrong Answer

Solution code:
n = int(input()) +1
t = list(map(int,input().split()))
v = list(map(int,input().split()))
t.append(0)
v.append(0)

vs = [0 for i in range(sum(t)*2+1)]
t_index = 0
time_s = 0 
v_index = 0
for i in range(1,len(vs)):
  vs[i] = min(vs[i-1]+0.5, v[t_index], v[t_index+1] + (t[t_index]-time_s)-0.5)
  time_s += 0.5
  if time_s == t[t_index]:
    t_index += 1
    time_s = 0

ans = 0
for i in range(len(vs)-1):
  ans += (vs[i]+vs[i+1])/4
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input()) +1
t = list(map(int,input().split()))
v = list(map(int,input().split()))
t.append(0)
v.append(0)

vs = [0 for i in range(sum(t)*2+1)]
t_index = 0
time_s = 0 
v_index = 0
for i in range(1,len(vs)):
  vs[i] = min(vs[i-1]+0.5, v[t_index], v[t_index+1] + (t[t_index]-time_s)-0.5)
  time_s += 0.5
  if time_s == t[t_index]:
    t_index += 1
    time_s = 0

ans = 0
for i in range(len(vs)-1):
  ans += (vs[i]+vs[i+1])/4
print(round(ans,4))

Submission status: Wrong Answer

Solution code:
n = int(input()) +1
t = list(map(int,input().split()))
v = list(map(int,input().split()))
t.append(0)
v.append(0)

vs = [0 for i in range(sum(t)*2+1)]
t_index = 0
time_s = 0 
v_index = 0
for i in range(1,len(vs)):
  vs[i] = min(vs[i-1]+0.5, v[t_index], v[t_index+1] + (t[t_index]-time_s)-0.5)
  #print('index:{}, time:{}, vs[i]:{}'.format(i,time_s,vs[i]))
  time_s += 0.5
  if time_s == t[t_index]:
    t_index += 1
    time_s =0

ans = 0
for i in range(len(vs)-1):
  ans += (vs[i]+vs[i+1])/4
print(ans)