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:
N = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))

T = T + [0]
V = [0] + V + [0]

SumT = [0] * (N+2)
for i in range(N+1):
    SumT[i+1] = SumT[i] + T[i]
Tmax = SumT[N+1]

#print(SumT)
#print(V)
area = 0
prev_v = 0
i = 0.5
j = 1
while i <= Tmax:
    if i > SumT[j]:
        j += 1
    now_v = min(min(prev_v + 0.5, V[j]), min(V[j], (SumT[j] - i) + V[j+1]))
    area += (prev_v + now_v) * 0.25
    #print(i,now_v)
    prev_v = now_v
    i += 0.5
    
print(area)

Submission status: Wrong Answer

Solution code:
n = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))
t.append(0)
v.append(0)
speed = 0
ans = 0
for i in range(n):
  print(ans,speed)
  if v[i] <= v[i+1]:
    if t[i] >= v[i] -speed:
      ans += (v[i]+speed)*v[i]/2 + (t[i]-v[i])*v[i]
      speed = v[i]
    else:
      ans += (speed+t[i])*t[i]/2
      speed = t[i]
  else:
    if 2 * v[i] - v[i-1] > t[i]:
      a = (v[i+1] + t[i])/2
      ans += (a+speed)*(abs(a-speed))/2 + (a+v[i+1])*(abs(a-v[i+1]))/2
    else:
      ans += (v[i]+speed)*(abs(v[i]-speed))/2 + (v[i]+v[i+1])*(abs(v[i]-v[i+1]))/2 + v[i] * (t[i] -2 * v[i] + v[i+1])
    speed = v[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- 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, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    df = 0.5
    # t, v
    vs = [0] * int(sum(T)*(1/df) + 2)

    i = 1
    for t, v in zip(T, V):
        # error_print(vs)
        if vs[i-1] > v:
            diff = vs[i-1]-v
            for j in range(0, int(diff/df)):
                if vs[i-1-j] <= v + j*df:
                    break
                vs[i-1-j] = min(vs[i-1-j], v + j*df)
        for _ in range(t*int(1/df)):
            vs[i] = min(vs[i-1]+df, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*df
        ans += (d*df)/2
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()
    print(slv(N, T, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- 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, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    df = 0.5
    vs = [0] * int(sum(T)*(1/df) + 2)

    i = 1
    for t, v in zip(T, V):
        # error_print(vs)
        if vs[i-1] > v:
            diff = vs[i-1]-v
            for j in range(0, int(diff/df)):
                if j == 0:
                    vs[i-1-j] = min(vs[i-1-j], v)
                else:
                    vs[i-1-j] = min(vs[i-1-j], vs[i-1-j+1] + df)
        for _ in range(t*int(1/df)):
            vs[i] = min(vs[i-1]+df, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*df
        ans += (d*df)/2
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()
    print(slv(N, T, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- 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, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    df = 0.5
    vs = [0] * int(sum(T)*(1/df) + 2)

    i = 1
    for t, v in zip(T, V):
        error_print(vs)
        if vs[i-1] > v:
            diff = vs[i-1]-v
            for j in range(0, int(diff/df)):
                if j == 0:
                    vs[i-1-j] = min(vs[i-1-j], v)
                else:
                    vs[i-1-j] = min(vs[i-1-j], vs[i-1-j+1] + df)
        for _ in range(t*int(1/df)):
            vs[i] = min(vs[i-1]+df, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*df
        ans += (d*df)/2
    print(vs)
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()
    print(slv(N, T, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- 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, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    df = 0.1
    # t, v
    vs = [0] * int(sum(T)*(1/df) + 1)

    i = 1
    for t, v in zip(T, V):
        if vs[i-1] > v:
            diff = vs[i-1]-v
            for j in range(int(diff/df)):
                vs[i-1-j] = min(vs[i-1-j], v + j*df)
        for _ in range(t*int(1/df)):
            vs[i] = min(vs[i-1]+df, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*df
        ans += (d*df)/2
    # print(vs)
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()
    print(slv(N, T, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- 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, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    df = 0.001
    # t, v
    vs = [0] * int(sum(T)*(1/df) + 1)

    i = 1
    for t, v in zip(T, V):
        if vs[i-1] > v:
            diff = vs[i-1]-v
            for j in range(int(diff/df)):
                vs[i-1-j] = min(vs[i-1-j], v + j*df)
        for _ in range(t*int(1/df)):
            vs[i] += min(vs[i-1]+df, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*df
        ans += (d*df)/2
    # print(vs)
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()
    print(slv(N, T, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- 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, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    df = 0.01
    # t, v
    vs = [0] * int(sum(T)*(1/df) + 1)

    i = 1
    for t, v in zip(T, V):
        if vs[i-1] > v:
            diff = vs[i-1]-v
            for j in range(int(diff/df)):
                vs[i-1-j] = min(vs[i-1-j], v + j*df)
        for _ in range(t*int(1/df)):
            vs[i] += min(vs[i-1]+df, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*df
        ans += (d*df)/2
    # print(vs)
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()
    print(slv(N, T, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- 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, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    df = 0.1
    # t, v
    vs = [0] * int(sum(T)*(1/df) + 1)

    i = 1
    for t, v in zip(T, V):
        if vs[i-1] > v:
            diff = vs[i-1]-v
            for j in range(int(diff/df)):
                vs[i-1-j] = min(vs[i-1-j], v + j*df)
        for _ in range(t*int(1/df)):
            vs[i] += min(vs[i-1]+df, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*df
        ans += (d*df)/2
    # print(vs)
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()
    print(slv(N, T, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- 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, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, T, V):

    T.append(0)
    V.append(0)

    # t, v
    vs = [0] * (sum(T)*2 + 1)

    i = 1
    for t, v in zip(T, V):
        if vs[i-1] > v:
            diff = vs[i-1]-v
            for j in range(int(diff/0.5)):
                vs[i-1-j] = min(vs[i-1-j], v + j*0.5)
        for _ in range(t*2):
            vs[i] += min(vs[i-1]+0.5, v)
            i += 1

    ans = 0
    for i in range(len(vs)-1):
        d = vs[i+1] - vs[i]
        ans += vs[i]*0.5
        ans += (d*0.5)/2
    # print(vs)
    return ans


def main():
    N = read_int()
    T = read_int_n()
    V = read_int_n()
    print(slv(N, T, V))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
TS = [0]
for i in range(N):
    TS.append(TS[i] + T[i])
V = list(map(int, input().split()))
ans = 0
L = [[0,0]]
R = [[TS[-1],TS[-1]]]
VSort = sorted(enumerate(V), key=lambda x: x[1])
for i, v in VSort:
    limitL = max([c for c in L if c[0] < TS[i]+0.5], key=lambda x: x[1])
    limitR = min([c for c in R if c[0] > TS[i+1]-0.5], key=lambda x: x[1])
    vl = TS[i]-limitL[1]
    vr = limitR[1]-TS[i+1]
    v1, v2 = sorted([vl, vr])
    ans += v * T[i]
    if v1 > v:
        L.append([TS[i + 1], TS[i + 1] - v])
        R.append([TS[i], TS[i] + v])
        continue
    elif v2 > v:
        if v - v1 < T[i]:
            ans -= (v-v1)**2 / 2
        else:
            ans -= (v-v1)*T[i] - T[i] ** 2 / 2
    else:
        if 2 * v - v1 - v2 < T[i]:
            ans -= ((v-v1)**2 + (v-v2)**2) / 2
        else:
            ans -= (v-v1)*T[i] - ((T[i]+v2-v1)/2)**2 + (v2-v1)**2/2
    L.append([TS[i+1], TS[i+1]-v])
    R.append([TS[i], TS[i]+v])
print(ans)

Submission status: Wrong Answer

Solution code:
def solve_area(v):
    area = 0
    for i in range(1, len(v)):
        area += (v[i] + v[i-1]) * 0.25
    return area

def m():
    N = int(input())
    t = [int(i) for i in input().split()]
    v = [int(j) for j in input().split()]
    maxtime = sum(t)
    max_v = [0] * (maxtime*2+1)
    endpoint = 0
    for n in range(N):
        for k in range(endpoint, endpoint + t[n]*2):
            max_v[k+1] = v[n]
        endpoint = k +1

    max_v[0] = 0
    max_v[maxtime*2] = 0
    for m in range(1, maxtime*2+1):
        max_v[m] = min(max_v[m-1]+0.5, max_v[m])

    for p in range(maxtime*2 - 1, -1, -1):
        max_v[p] = min(max_v[p+1]+0.5, max_v[p])

    ans = solve_area(max_v)
    return ans

print(m())

Submission status: Wrong Answer

Solution code:
def solve_area(v):
    area = 0
    for i in range(1, len(v)):
        area += (v[i] + v[i-1]) * 0.25
    return area

def m():
    N = int(input())
    t = [int(i) for i in input().split()]
    v = [int(j) for j in input().split()]
    maxtime = sum(t)
    max_v = [0] * (maxtime*2+1)
    endpoint = 0
    for n in range(N):
        for k in range(endpoint, endpoint + t[n]*2):
            max_v[k] = v[n]
        endpoint = k +1

    max_v[0] = 0
    for m in range(1, maxtime*2+1):
        max_v[m] = min(max_v[m-1]+0.5, max_v[m])

    max_v[maxtime*2] = 0
    for p in range(maxtime*2 -1, 0, -1):
        max_v[p] = min(max_v[p+1]+0.5, max_v[p])

    ans = solve_area(max_v)
    return ans

print(m())

Submission status: Wrong Answer

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

# process
for i in range(1, N):
    t[i+1] += t[i]

fun1s = [(0, 0)]*(N+1)
for i in range(1, N+1):
    if i == N:
        fun1s[N] = (-1, t[N])
    else:
        fun1s[i] = (-1, t[i] + v[i+1])


def solve(p1, p2):
    (a1, b1) = p1
    (a2, b2) = p2

    (x, y) = (-1, -1)
    if a2 == 0:
        y = b2
        x = y - b1
    else:
        y = (b1 + b2) / 2
        x = y - b1
    return (x, y)

def solve2(p1, p2):
    (a1, b1) = p1 # a1 == 0
    (a2, b2) = p2 # a2 == -1

    y = b2
    x = b2 - b1
    
    return (x, y)

ans = 0
(nx, ny) = (0, 0)
for i in range(1, N+1):
    gx = t[i]

    tmp = (1e9, 0, -1)
    for k in range(i, N+1):
        (x, y) = solve((1, ny-nx), fun1s[k])
        if x < tmp[0]:
            tmp = (x, fun1s[k], y)
            
    ceil = v[i]
    (cx, cy) = solve((1, ny-nx), (0, ceil))
    if gx <= min(cx, tmp[0]):
        ans += ((ny + (t[i] - t[i-1])) * (gx - nx)) / 2
        ny = gx - nx
    elif tmp[0] < cx:
        ans += ((ny + tmp[2]) * (tmp[0] - nx)) / 2
        ans += ((tmp[2] + (tmp[2] - (gx - tmp[0]))) * (gx - tmp[0])) / 2

        ny = tmp[2] - (gx - tmp[0])
    else:
        ans += ((ny + cy) * (cx - nx)) / 2

        tmp = (1e9, 0, -1)
        for k in range(i, N+1):
            (x, y) = solve2((0, ceil), fun1s[k])
            if x < gx:
                tmp = (x, fun1s[k], y)

        if gx <= tmp[0]:
            ans += cy * (gx - cx)
            ny = cy
        else:
            ans += cy * (tmp[0] - cx)
            ans += ((cy + (cy - (gx - tmp[0]))) * (gx - tmp[0])) / 2

            ny = cy - (gx - tmp[0])

    nx = gx

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))
v = [0]*(sum(T)*2+1)
t,Ti = 0,0
for i in range(N):
    Ti += T[i]*2
    v[t] = min(v[t],V[i])
    while t < Ti:
        if v[t] < V[i]:
            v[t+1] = v[t]+0.5
        else:
            v[t+1] = min(v[t],V[i])
        t += 1
sumT = sum(T)*2
v[sumT] = 0
t,Ti = sumT,sumT
for i in range(N):
    Ti -= T[N-i-1]
    while t > Ti:
        if v[t-1] > v[t]+.5:
            v[t-1] = v[t]+0.5
        t -= 1
Ans = 0
for i in range(sumT):
    Ans += (v[i]+v[i+1])*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()))
v = [0]*(sum(T)*2+1)
t,Ti = 0,0
for i in range(N):
    Ti += T[i]*2
    v[t] = min(v[t],V[i])
    while t < Ti:
        if v[t] < V[i]:
            v[t+1] = v[t]+0.5
        else:
            v[t+1] = min(v[t],V[i])
        t += 1
sumT = sum(T)*2
v[sumT] = 0
t,Ti = sumT,sumT
for i in range(N):
    Ti -= T[N-i-1]
    while t > Ti:
        if v[t-1] > v[t]+-.5:
            v[t-1] = v[t]+0.5
        t -= 1
Ans = 0
for i in range(sumT):
    Ans += (v[i]+v[i+1])*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()))
v = [0]*(sum(T)+1)
t,Ti = 0,0
for i in range(N):
    Ti += T[i]
    v[t] = min(v[t],V[i])
    while t < Ti:
        if v[t] < V[i]:
            v[t+1] = v[t]+1
        else:
            v[t+1] = min(v[t],V[i])
        t += 1
sumT = sum(T)
v[sumT] = 0
t,Ti = sumT,sumT
for i in range(N):
    Ti -= T[N-i-1]
    while t > Ti:
        if v[t-1] > v[t]+1:
            v[t-1] = v[t]+1
        t -= 1
Ans = 0
for i in range(sumT):
    Ans += (v[i]+v[i+1])/2

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()]
M = []

for i in range(n):
    M += [V[i]]*T[i]*2
   
if n % 2 == 0:
    M = [0] + M
    M[-1] = 0
else:
    M[0] = 0
    M += [0]



for i in range(1,len(M)):
    M[i] = min(M[i],M[i-1]+0.5)
    
for i in range(len(M)-2,0,-1):
    M[i] = min(M[i],M[i+1]+0.5)
    
ans = 0
for i in range(1,len(M)):
    ans += 0.5*(M[i]+M[i-1])*0.5

print(ans)

Submission status: Wrong Answer

Solution code:
def speed_limit(cond_i, time):
    if time < t[cond_i-1]:
        return v[cond_i] + (t[cond_i-1] - time)
    elif time < t[cond_i]:
        return v[cond_i]
    else:
        return v[cond_i] + (time - t[cond_i])

N = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))
t = [0] + t
v = [0] + v
for i in range(1,N+1):
    t[i] = t[i-1]+t[i]
#print(t)
#print(v)
v_possible = [0]*(2*t[N])
for i in range(1,2*t[N]):
    v_possible[i] = min(i*0.5, t[N]-i*0.5)
    for j in range(0, N, 1):
        v_possible[i] = min(v_possible[i], speed_limit(j, i*0.5))


#print(t)
#print(v)
#print(v_possible)
ans = sum(v_possible)*0.5
print(ans)

Submission status: Wrong Answer

Solution code:
def speed_limit(cond_i, time):
    if time < t[cond_i-1]:
        return v[cond_i] + (t[cond_i-1] - time)
    elif time < t[cond_i]:
        return v[cond_i]
    else:
        return v[cond_i] + (time - t[cond_i])

N = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))
t = [0] + t
v = [0] + v
for i in range(1,N+1):
    t[i] = t[i-1]+t[i]
#print(t)
#print(v)
v_possible = [0]*(2*t[N])
for i in range(1,2*t[N]):
    v_possible[i] = min(i*0.5, t[N]-i*0.5)
    for j in range(0, N, 1):
        v_possible[i] = min(v_possible[i], speed_limit(j, i*0.5))


print(t)
print(v)
print(v_possible)
ans = sum(v_possible)*0.5
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=[int(x) for x in input().split()]
V=[int(x) for x in input().split()]
V.append(0)
NV=0
ans=0

def calc(t,v,nxv):
  global NV
  res=0
  remainT=t
  for i in range(t*2):
    if remainT-0.5>=(NV+0.5-nxv) and NV+0.5<=v:
      remainT-=0.5
      NV+=0.5
      res+=(NV*0.5+0.5**3)
    elif remainT-0.5==(NV-0.5-nxv):
      remainT-=0.5
      NV-=0.5
      res+=(NV*0.5-0.5**3)
    else:
      remainT-=0.5
      res+=NV*0.5
  return res
    
for i in range(N):
  ans+=calc(T[i],V[i],V[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=[int(x) for x in input().split()]
V=[int(x) for x in input().split()]
V.append(0)
NV=0
ans=0

def calc(t,v,nxv):
  global NV
  res=0
  remainT=t
  for i in range(t*2):
    if remainT-0.5>=(NV+0.5-nxv) and NV<v:
      remainT-=0.5
      NV+=0.5
      res+=(NV*0.5+0.5**3)
    elif remainT-0.5==(NV-0.5-nxv):
      remainT-=0.5
      NV-=0.5
      res+=(NV*0.5-0.5**3)
    else:
      remainT-=0.5
      res+=NV*0.5
  return res
    
for i in range(N):
  ans+=calc(T[i],V[i],V[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))
T.append(0)
V.append(0)
T = T[::-1]
V = V[::-1]

max_time = sum(T)
time_limit = T.pop()
speed_limit = V.pop()
time_next = T.pop()
speed_next = V.pop()

ans = 0
speed = 0
cul_time = 0
all_remain_time = max_time
for time in numpy.arange(0, max_time+0.5, 0.5):
    all_remain_time -= 0.5
    remain_time = time_limit - time + cul_time
    ans += speed * 0.5

    if remain_time == 0:
        cul_time += time_limit
        time_limit = time_next
        speed_limit = speed_next
        if T:
            time_next = T.pop()
            speed_next = V.pop()

    if speed_next < speed_limit:
        if remain_time <= speed - speed_next:
            if (remain_time == 0) & (speed <= speed_limit) & (all_remain_time >= speed+0.5):
                speed += 1
            speed = max(speed-0.5, 0)
        elif (speed + 0.5 <= speed_limit) & (all_remain_time >= speed+0.5):
            speed += 0.5
    else:
        if (speed + 0.5 <= speed_limit) & (all_remain_time >= speed+0.5):
            speed += 0.5

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))
T.append(0)
V.append(0)
T = T[::-1]
V = V[::-1]

max_time = sum(T)
time_limit = T.pop()
speed_limit = V.pop()
time_next = T.pop()
speed_next = V.pop()

ans = 0
speed = 0
cul_time = 0
all_remain_time = max_time
for time in numpy.arange(0, max_time+0.5, 0.5):
    all_remain_time -= 0.5
    remain_time = time_limit - time + cul_time
    ans += speed * 0.5

    if remain_time == 0:
        cul_time += time_limit
        time_limit = time_next
        speed_limit = speed_next
        if T:
            time_next = T.pop()
            speed_next = V.pop()

    if speed_next < speed_limit:
        if remain_time <= speed - speed_next:
            if (remain_time == 0) & (speed <= speed_limit) & (all_remain_time >= speed):
                speed += 1
            speed = max(speed-0.5, 0)
        elif (speed + 0.5 <= speed_limit) & (all_remain_time >= speed+0.5):
            speed += 0.5
    else:
        if (speed + 0.5 <= speed_limit) & (all_remain_time >= speed+0.5):
            speed += 0.5

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))
T.append(0)
V.append(0)
T = T[::-1]
V = V[::-1]

max_time = sum(T)
time_limit = T.pop()
speed_limit = V.pop()
time_next = T.pop()
speed_next = V.pop()

ans = 0
speed = 0
cul_time = 0
all_remain_time = max_time
for time in numpy.arange(0, max_time+0.5, 0.5):
    all_remain_time -= 0.5
    remain_time = time_limit - time + cul_time
    ans += speed * 0.5

    if remain_time == 0:
        cul_time += time_limit
        time_limit = time_next
        speed_limit = speed_next
        if T:
            time_next = T.pop()
            speed_next = V.pop()

    if speed_next < speed_limit:
        if remain_time <= speed - speed_next:
            if (remain_time == 0) & (speed <= speed_limit) & (all_remain_time >= speed):
                speed += 1
            speed = max(speed-0.5, 0)
        elif (speed + 0.5 <= speed_limit) & (all_remain_time >= speed):
            speed += 0.5
    else:
        if (speed + 0.5 <= speed_limit) & (all_remain_time >= speed):
            speed += 0.5

print(ans)