output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s738394748 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | K, S = map(int,input()split())
c = 0
for i in range(K+1):
for j in range(K+1):
z = S - i - j
if 0 <= z and z <= K:
c += 1
print(c) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s063027102 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | s,k=map(int,input().split())
print(len[z for x in range(0,k+1) for y in range(0,k+1) if 0<=s-x-y<=k]) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s989525160 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | a, b, c = input().split(",")
print(a, b, c)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s640346335 | Accepted | p03835 | The input is given from Standard Input in the following format:
K S | import sys
from sys import exit
from collections import deque
from bisect import (
bisect_left,
bisect_right,
insort_left,
insort_right,
) # func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9 + 7
def lcm(x, y):
return x * y // gcd(x, y)
def lgcd(l):
return reduce(gcd, l)
def llcm(l):
return reduce(lcm, l)
def powmod(n, i, mod):
return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod)
def div2(x):
return x.bit_length()
def div10(x):
return len(str(x)) - (x == 0)
def perm(n, mod=None):
ans = 1
for i in range(1, n + 1):
ans *= i
if mod != None:
ans %= mod
return ans
def intput():
return int(input())
def mint():
return map(int, input().split())
def lint():
return list(map(int, input().split()))
def ilint():
return int(input()), list(map(int, input().split()))
def judge(x, l=["Yes", "No"]):
print(l[0] if x else l[1])
def lprint(l, sep="\n"):
for x in l:
print(x, end=sep)
def ston(c, c0="a"):
return ord(c) - ord(c0)
def ntos(x, c0="a"):
return chr(x + ord(c0))
class counter(dict):
def __init__(self, *args):
super().__init__(args)
def add(self, x):
self.setdefault(x, 0)
self[x] += 1
class comb:
def __init__(self, n, mod=None):
self.l = [1]
self.n = n
self.mod = mod
def get(self, k):
l, n, mod = self.l, self.n, self.mod
k = n - k if k > n // 2 else k
while len(l) <= k:
i = len(l)
l.append(
l[i - 1] * (n + 1 - i) // i
if mod == None
else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod
)
return l[k]
K, S = mint()
ans = 0
for X in range(K + 1):
for Y in range(K + 1):
if S - X - Y in range(K + 1):
ans += 1
print(ans)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s310832251 | Accepted | p03835 | The input is given from Standard Input in the following format:
K S | from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
return input()
def LS():
return [i for i in input().split()]
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def NI(n):
return [int(input()) for i in range(n)]
def NI_(n):
return [int(input()) - 1 for i in range(n)]
def StoI():
return [ord(i) - 97 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def LtoS(ls):
return "".join([chr(i + 97) for i in ls])
def GI(V, E, Directed=False, index=0):
org_inp = []
g = [[] for i in range(n)]
for i in range(E):
inp = LI()
org_inp.append(inp)
if index == 0:
inp[0] -= 1
inp[1] -= 1
if len(inp) == 2:
a, b = inp
g[a].append(b)
if not Directed:
g[b].append(a)
elif len(inp) == 3:
a, b, c = inp
aa = (inp[0], inp[2])
bb = (inp[1], inp[2])
g[a].append(bb)
if not Directed:
g[b].append(aa)
return g, org_inp
def GGI(h, w, search=None, replacement_of_found=".", mp_def={"#": 1, ".": 0}):
# h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
mp = [1] * (w + 2)
found = {}
for i in range(h):
s = input()
for char in search:
if char in s:
found[char] = (i + 1) * (w + 2) + s.index(char) + 1
mp_def[char] = mp_def[replacement_of_found]
mp += [1] + [mp_def[j] for j in s] + [1]
mp += [1] * (w + 2)
return h + 2, w + 2, mp, found
def bit_combination(k, n=2):
rt = []
for tb in range(n**k):
s = [tb // (n**bt) % n for bt in range(k)]
rt += [s]
return rt
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YN = ["Yes", "No"]
mo = 10**9 + 7
inf = float("inf")
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().rstrip()
def ran_input():
import random
n = random.randint(4, 16)
rmin, rmax = 1, 10
a = [random.randint(rmin, rmax) for _ in range(n)]
return n, a
show_flg = False
show_flg = True
ans = 0
k, s = LI()
for x in range(k + 1):
for y in range(k + 1):
if 0 <= s - x - y <= k:
ans += 1
print(ans)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s974361686 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s=map(int,input().split())
ans=0
for i in range(k+1):
for j in range(k+1-i):
if s-i-j<=2500
ans+=1
print(ans) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s654376154 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | K,S=map(int,input().split())
ans=0
for x in range(K+1):
for y in range(K+1):
for z in range(K+1):
if x+y+z=S:
ans+=1
print(ans) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s914016928 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s = map(int,input().split())
cnt = 0
for x in range(k+1):
for y in range(k+1):
if x + y <= s and x + y >= s - k
cnt += 1
print(cnt) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s144585745 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | K, S = map(int, input().split())
cnt = 0
for i in range(K+1):
for j in range(K+1):
k = S - i -j:
if k <= 0 and S <= k:
cnt += 1
print(cnt)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s490998631 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k, s = map(int, input().split())
count = 0
for x in range(k+1):
for y in range(k+1):
z = s - x - y
if 0 <= z and z <= k
count += 1
print(count)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s867794230 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | K, S = map(int, input().split())
count=0
for x in range(K+1):
for y in range(K+1):
for z in range(K+1)
if x+y+z == S:
count += 1
print(count) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s845247882 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s=map(int, input().split())
x+y+z=s
count=0
for x in range(k+1):
for y in range(k+1):
for z in range(k+1):
if x+y+z=s:
count+=1
print(count) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s465251624 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k, s = map(int, input().split())
ans = 0
for x in range(k+1):
for y in range(k+1):
z = s-x-y
if k >= z >= 0:
ans += 1
print(ans)) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s876202401 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s=map(int, input().split())
x+y+z=s
count=0
for x in range(k+1):
for y in range(k+1):
for z in range(z+1):
if x+y+z=s:
count+=1
print(count) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s641167244 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k, s = map(int, input().split())
ans = 0
for x in range(k+a):
for y in range(k+1):
z = s-x-y
if k >= z >= 0:
ans += 1
print(ans)) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s648244894 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | count=0
k,s=map(int,input().split())
for i in range(s):
for j in range(s-i):
for m in range(s-i-j):
if i<=k ans j<=k ans m<=k:
count+=1
print(count) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s368133133 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | K,S=map(int,inpit().split())
conut=0
for x in range(K+1):
for y in range(K+1):
for z in range(K+1):
if x+y+z=S:
count+=1
print(count)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s486356252 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | K,S = map(int, input().split())
ans = 0
for i in range(K+1):
if 0<= S-i <= K:
ans += (S-i)+1
elif S-i <= 2K:
a = (S-i) -K
ans += (K-a)+1
print(ans)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s062287604 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | def comb(n, r):
if r == 0 or n == r: return 1
else: return comb(n-1, r) + comb(n-1, r-1)
k, s = map(int, input().split())
if s < k: print(comb(s+2, 2))
elif s < 2k: print(3*comb(s-k+2, 2))
else: print(3*comb(s-2k+2,2)) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s096881540 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | def comb(n, r):
if r == 0 or n == r: return 1
else: return comb(n-1, r) + comb(n-1, r-1)
k, s = map(int, input().split())
if s <= k: print(comb(s+2, 2))
elif s <= 2*k: print(3*comb(s-k+2, 2))
else: print(3*comb(s-2k+2,2)) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s914872584 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | # include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main()
{
int K, S;
cin >> K >> S;
int cnt = 0;
rep (X, K+1)
{
rep (Y, K+1)
{
rep (Z, K+1)
{
if (X + Y + Z == S)
{
cnt++;
}
}
}
}
cout << cnt << "\n";
return 0;
}
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s411610482 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | import numpy as np
K,S = map(int, input().split())
def main():
cnt = 0
for x in range(K+1):
for y in range(K+1):
for z in range(K+1):
if x+y+z == S
cnt += 1
else:
pass
print(cnt)
if __name__ == "__main__":
main()
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s417792820 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s = map(int,input().split())
ans = 0
for i in range(k + 1):
if i > s;break
for j in range(k + 1):
if i + j > s;break
for k in range(k + 1):
if i + j + k > s;break
if i + j + k == s:ans+=1
print (ans)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s140369525 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s = map(int, input().split())
l = 0
if s <= k:
l = int((k+2)(k+1)/2)
else:
for x in range(0,k+1):
if s-x > 2k:
l += 0
elif k < s-x <= 2k:
l += 2*k - s + x + 1
elif s-x <= k:
l += s-x+1
print(l) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s969110356 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s = [int(i) for i in input().split()]
def a(n):
if n == 1:
return n
else:
return n + a(n-1)
if k >= s:
print(a(s+1))
elif s >= 2 * k and s <= 3 * k:
print(a(3 * k - s + 1))
elif s > k and s < 2 * k:
print(a(s + 1) - 3 * a(s - k))
else: | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s410471021 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | fn main() {
let s: i32 = read();
let k: i32 = read();
let mut ans = 0;
for i in 0..k+1 {
for j in 0..k+1 {
for l in 0..k+1 {
if i+j+l == s {
ans += 1;
}
}
}
}
println!("{}", ans);
}
// 以下関数
use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
let stdin = stdin();
let stdin = stdin.lock();
let token: String = stdin
.bytes()
.map(|c| c.expect("failed to read char") as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().expect("failed to parse token")
}
pub const MOD: u64 = 1_000_000_007;
pub fn is_prime(n: i32) -> bool {
if n < 2 {
return false;
} else if n == 2 {
return true;
}
let mut i = 2;
while i * i < n {
if n % i == 0 {
return false;
} else {
i += 1;
continue;
}
}
true
}
pub fn lcm(mut n: i32, mut m: i32) -> i32 {
n = if n > m { m } else { n };
m = if n > m { n } else { m };
let mut i = n;
while i % m != 0 {
i += n;
}
i
}
pub fn abs(n: i32) -> i32 {
if n >= 0 {
n
} else {
-n
}
}
pub fn max(n: i32, m: i32) -> i32 {
if n >= m {
n
} else {
m
}
}
pub fn min(n: i32, m: i32) -> i32 {
if n <= m {
n
} else {
m
}
}
pub fn factorial(n: u32) -> u32 {
if n == 0 {
return 1;
}
let mut r = n;
for i in 0..n - 1 {
r *= n - i - 1;
}
r
}
pub fn combination(n: u32, m: u32) -> u32 {
factorial(n) / factorial(m) / factorial(n - m)
}
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s474801229 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | K, S = map(int, input().split)
count = 0
for x in range(K):
if x == S:
count++
break
for y in range(K):
if x + y == S:
count++
break
for z in range(K):
if x + y + z == S:
count++
break
print(count) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s302751428 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | def f(K, S):
#ここに処理を書いてください
res = 0
for i in range(K+1):
for j in range(K+1):
if i + j <= S and S-i-j <= K:
res += 1
return res
in = list(map(int, input().split()))
print(f(in[0], in[1])) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s065212652 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | import numpy as np
import sys
x = [[int(i) for i in input().split()] for j in range(1)]
k = x[0][0]
s = x[0][1]
#k = 5
#s = 15
count = 0
for x in range(k+1):
if x = s:
count = count + 1
break
for y in range(k+1):
if s < x + y:
break
if x + y = s:
count = count + 1
break
for z in range(k+1):
if s - x - y < k:
count = count + 1
break
print(count)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s722717533 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s = map(int,input().split())
counter = 0
for i in range(k+1):
for m in range(k+1):
if 0 <= (s -i- m) <= k:
counter+= 1
print(counter)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s810211629 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | K, S = map(int, input().split())
print(len[1 for X in range(K+1) for Y in range(K+1) if 0<=S-X=Y<=K]) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s995729125 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | k,s=map(int,input().split())
ans = 0
for i in range(1,k+1):
for j in range(1,k;1):
if s-i-j<=k:
ans+=1
print(ans) | Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the number of the triples of X, Y and Z that satisfy the condition.
* * * | s094128312 | Runtime Error | p03835 | The input is given from Standard Input in the following format:
K S | a,s = map(int,input().split())
sum = 0
for i in range(0,a+1):
for j in range(0,a+1):
if s-i-j <= a:
sum + = 1
print(sum)
| Statement
You are given two integers K and S.
Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X, Y and Z are there such that X +
Y + Z = S? | [{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s658264485 | Runtime Error | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | import numpy as np
# inp = input
fin = open("case_21.txt")
inp = fin.readline
X, Y, A, B, C = map(int, inp().split())
red = np.array(list(map(int, inp().split())), np.int32)
green = np.array(list(map(int, inp().split())), np.int32)
white = np.array(list(map(int, inp().split())), np.int32)
fin.close()
red[::-1].sort()
green[::-1].sort()
white[::-1].sort()
idr = 0
idg = 0
idw = 0
total = 0.0
countr = 0
countg = 0
while X > countr and Y > countg:
if red[idr] > green[idg]:
# compare green 1st
if idw < C and green[idg] < white[idw]:
# eat white
total += white[idw]
idw += 1
else:
# eat green
total += green[idg]
idg += 1
countg += 1
else:
# compare red 1st
if idw < C and red[idr] < white[idw]:
# eat white
total += white[idw]
idw += 1
else:
# eat red
total += red[idr]
idr += 1
countr += 1
# eat remain
while X > countr:
# compare red 1st
if idw < C and red[idr] < white[idw]:
# eat white
total += white[idw]
idw += 1
else:
# eat red
total += red[idr]
idr += 1
countr += 1
while Y > countg:
# compare green 1st
if idw < C and green[idg] < white[idw]:
# eat white
total += white[idw]
idw += 1
else:
# eat green
total += green[idg]
idg += 1
countg += 1
print(int(total))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s383957270 | Runtime Error | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | x, y, a, b, c = [int(i) for i in input().split()]
red_list = [int(i) for i in input().split()]
green_list = [int(i) for i in input().split()]
non_col_list = [int(i) for i in input().split()]
red_list.sort()
green_list.sort()
non_col_list.sort()
eat_red = []
eat_green = []
for i in range(x):
eat_red.append(red_list.pop())
for i in range(y):
eat_green.append(green_list.pop())
# eat_redにX個の赤いリンゴの美味しさ(降順)
# eat_greenにY個の緑のリンゴの美味しさ(降順)
# non_col_listにC個の無色のリンゴの美味しさ(昇順)
ans = 0
def irekae(eat_list, non_col_list):
if non_col_list == []:
return False
global ans
taishou = eat_list.pop()
non_col = non_col_list.pop()
if taishou < non_col:
ans += non_col
return True
else:
eat_list.append(taishou)
return False
while True:
if eat_red[-1] < eat_green[-1]:
if not irekae(eat_red, non_col_list):
break
else:
if not irekae(eat_green, non_col_list):
break
print(ans + sum(eat_green) + sum(eat_red))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s744842342 | Runtime Error | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | #!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = map(int, read().split())
AB = zip(m, m)
MOD = 10**9 + 7
graph = [[] for _ in range(N + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
fact = [1] * (N + 10)
for n in range(1, N + 10):
fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
fact_inv[n - 1] = fact_inv[n] * n % MOD
size_d = [0] * (N + 1)
dp_d = [1] * (N + 1)
for v in order[::-1]:
dp_d[v] *= fact[size_d[v]]
dp_d[v] %= MOD
p = parent[v]
s = size_d[v] + 1
size_d[p] += s
dp_d[p] *= fact_inv[s] * dp_d[v]
dp_d[p] %= MOD
size_u = [N - 2 - x for x in size_d]
dp_u = [1] * (N + 1)
for v in order[1:]:
p = parent[v]
x = dp_d[p]
x *= dp_u[p]
x *= fact_inv[size_d[p]]
x *= fact[size_d[v] + 1]
x *= pow(dp_d[v], MOD - 2, MOD)
x *= fact[size_u[v]]
x *= fact_inv[size_u[p] + 1]
dp_u[v] = x % MOD
for xd, xu, sd, su in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
su += 1
x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % MOD
print(x)
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s542994390 | Runtime Error | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | import sys
sys.setrecursionlimit(100000)
class fact:
def __init__(self, i, mod):
self.l = [1] * (i + 1)
for i in range(1, i + 1):
self.l[i] = self.l[i - 1] * i
self.mod = mod
self.g1 = [1, 1]
self.g2 = [1, 1]
inverse = [0, 1]
for i in range(2, 2 * (10**5) + 1):
self.g1.append((self.g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
self.g2.append((self.g2[-1] * inverse[-1]) % mod)
def main():
N = int(input())
d = {}
mod = 10**9 + 7
f = fact(N, mod)
for i in range(N - 1):
a, b = map(int, input().split())
if a in d:
d[a].append(b)
else:
d[a] = [b]
if b in d:
d[b].append(a)
else:
d[b] = [a]
for i in range(1, N + 1):
v = set()
r, t = solve(i, N, v, f, d)
print(r % mod)
def solve(n, a, v, f, d):
v.add(n)
x = 0
unv = []
for i in d[n]:
if i not in v:
x += 1
unv.append(i)
if x == 1:
r, t = solve(unv[0], a - 1, v, f, d)
return r, t + 1
if x == 0:
return 1, 1
t = 1
r = 1
for i in unv:
rr, tt = solve(i, a - 1, v, f, d)
t += tt
r *= rr
r *= f.g2[tt]
r *= f.l[t - 1]
return r, t
main()
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s258910116 | Accepted | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | x, y, a, b, c = map(int, input().split())
Lista = sorted(list(map(int, input().split())), reverse=True)
Listb = sorted(list(map(int, input().split())), reverse=True)
Listc = sorted(list(map(int, input().split())), reverse=True)
if x < a:
del Lista[x:a]
if y < b:
del Listb[y:b]
List = sorted(Lista + Listb, reverse=True)
i = -1
for n in range(min(x + y, c)):
if List[-n - 1] < Listc[n]:
i = n
else:
break
del List[x + y - i - 1 : x + y]
del Listc[i + 1 : c]
print(sum(List) + sum(Listc))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s182640806 | Runtime Error | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | import sys
sys.setrecursionlimit(10**8)
N, X, Y = map(int, input().split())
ans = [0 for _ in range(N)]
link = [[]] + [[2]] + [[i - 1, i + 1] for i in range(2, N)] + [[N - 1]]
link[X].append(Y)
link[Y].append(X)
def f(p, length, moto):
ans[length] += 1
for data in link[p]:
if data != moto:
f(data, length + 1, p)
for i in range(1, N + 1):
for data in link[i]:
f(data, 1, i)
print(*ans[1:], sep="\n")
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s908574705 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | x, y, a, b, c = map(int, input().split())
p = input().split()
p = [int(s) for s in p]
q = input().split()
q = [int(s) for s in q]
r = input().split()
r = [int(s) for s in r]
reds = sorted(p, reverse=True)
reds = reds[:x]
greens = sorted(q, reverse=True)
greens = greens[:y]
allints = sorted(reds + greens)
minofall = allints[0]
r = [i for i in r if i > minofall]
del allints[: len(r)]
print(sum(allints + r))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s690062480 | Accepted | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | from collections import deque
x, y, a, b, c = list(map(int, input().split()))
pl = list(map(int, input().split()))
ql = list(map(int, input().split()))
rl = list(map(int, input().split()))
pl.sort(reverse=True)
ql.sort(reverse=True)
rl.sort(reverse=True)
ans = 0
if x > a:
ans += sum(pl)
dif_x = x - a
ans += rl[:dif_x]
del rl[:dif_x]
if y > b:
ans += sum(ql)
dif_y = y - b
ans += sum(rl[:dif_y])
else:
qd = deque(ql)
rd = deque(rl)
for i in range(y):
if qd and rd:
if qd[0] > rd[0]:
ans += qd.popleft()
else:
ans += rd.popleft()
else:
if qd:
ans += qd.popleft()
else:
ans += rd.popleft()
else:
if y > b:
ans += sum(ql)
dif_y = y - b
ans += rl[:dif_y]
del rl[:dif_y]
pd = deque(pl)
rd = deque(rl)
for i in range(x):
if pd and rd:
if pd[0] > rd[0]:
ans += pd.popleft()
else:
ans += rd.popleft()
else:
if pd:
ans += pd.popleft()
else:
ans += rd.popleft()
else:
pd = deque(pl)
qd = deque(ql)
rd = deque(rl)
c_x = 0
c_y = 0
for i in range(x + y):
if pd and qd and rd:
if (pd[0] == max([pd[0], qd[0], rd[0]]) and c_x < x) or (
not c_y < y and pd[0] >= rd[0]
):
ans += pd.popleft()
c_x += 1
elif (qd[0] == max([pd[0], qd[0], rd[0]]) and c_y < y) or (
not c_x < x and qd[0] >= rd[0]
):
ans += qd.popleft()
c_y += 1
else:
ans += rd.popleft()
else:
target = [-1, -1, -1]
if pd:
target[0] = pd[0]
if qd:
target[1] = qd[0]
if rd:
target[2] = rd[0]
t_max = max(target)
ans += t_max
idx = target.index(t_max)
if idx == 0:
pd.popleft()
elif idx == 1:
qd.popleft()
else:
rd.popleft()
print(ans)
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s216249102 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | #!/usr/bin/env python3
from itertools import chain
import sys
try:
from typing import List
except ImportError:
pass
def solve(
X: int,
Y: int,
A: int,
B: int,
C: int,
p: "List[int]",
q: "List[int]",
r: "List[int]",
):
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
xy = sorted(
chain(
((p[i], 0) for i in range(X)),
((q[i], 1) for i in range(Y)),
)
)
x = X
y = Y
a = 0
while a < X + Y and X + Y - x - y < C and xy[a][0] < r[X + Y - x - y]:
if xy[a][1] == 0 and x > 0:
x -= 1
a += 1
if xy[a][1] == 1 and y > 0:
y -= 1
a += 1
print(sum(p[:x]) + sum(q[:y]) + sum(r[: X + Y - x - y]))
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
X = int(next(tokens)) # type: int
Y = int(next(tokens)) # type: int
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
p = [int(next(tokens)) for _ in range(A)] # type: "List[int]"
q = [int(next(tokens)) for _ in range(B)] # type: "List[int]"
r = [int(next(tokens)) for _ in range(C)] # type: "List[int]"
solve(X, Y, A, B, C, p, q, r)
if __name__ == "__main__":
main()
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s741673652 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)[:X]
Q = sorted(list(map(int, input().split())), reverse=True)[:Y]
R = sorted(list(map(int, input().split())))
ans = sum(P) + sum(Q)
idxp = -1
idxq = -1
for ri in range(C):
r = R[ri]
if idxp >= -X and idxq >= -Y:
if P[idxp] <= Q[idxq] and P[idxp] < R[ri]:
ans += R[ri] - P[idxp]
idxp -= 1
elif Q[idxq] <= P[idxp] and Q[idxq] < R[ri]:
ans += R[ri] - Q[idxq]
idxq -= 1
elif idxp >= -X:
if P[idxp] < R[ri]:
ans += R[ri] - P[idxp]
idxp -= 1
elif idxq >= -Y:
if Q[idxq] < R[ri]:
ans += R[ri] - Q[idxq]
idxq -= 1
print(ans)
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s824623346 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | x, y, a, b, c = map(int, input().split())
xx = x
yy = y
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))
r = sorted(list(map(int, input().split())))[::-1]
z = 0
rr = r[0]
for i in range(a)[::-1]:
if p[i] >= rr and x:
z += p[i]
x -= 1
for i in range(b)[::-1]:
if q[i] >= rr and y:
z += q[i]
y -= 1
ta = 0
rl = 0
if x:
p = p[: a - xx + x]
p = p[::-1]
pl = 0
for _ in range(x):
if rl < c:
if p[pl] < r[rl]:
ta += r[rl]
rl += 1
else:
ta += p[pl]
pl += 1
if y:
q = q[: b - yy + y]
q = q[::-1]
ql = 0
for _ in range(y):
if rl < c:
if q[ql] < r[rl]:
ta += r[rl]
rl += 1
else:
ta += q[ql]
ql += 1
tb = 0
rl = 0
if y:
ql = 0
for _ in range(y):
if rl < c:
if q[ql] < r[rl]:
tb += r[rl]
rl += 1
else:
tb += q[ql]
ql += 1
if x:
pl = 0
for _ in range(x):
if rl < c:
if p[pl] < r[rl]:
tb += r[rl]
rl += 1
else:
tb += p[pl]
pl += 1
print(z + max(ta, tb))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s840596186 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | from heapq import heappush, heappop
def main():
X, Y, A, B, C = map(int, input().split())
P = []
Q = []
R = []
for v in input().split():
heappush(P, -int(v))
for v in input().split():
heappush(Q, -int(v))
for v in input().split():
heappush(R, -int(v))
score = 0
cp = 0
cq = 0
cr = 0
XY = X + Y
while (
len(P) > 0
and len(Q) > 0
and len(R) > 0
and cp < X
and cq < Y
and cp + cq + cr < XY
):
p = -P[0]
q = -Q[0]
r = -R[0]
if p > q:
if p > r:
score -= heappop(P)
cp += 1
else:
score -= heappop(R)
cr += 1
else:
if q > r:
score -= heappop(Q)
cq += 1
else:
score -= heappop(R)
cr += 1
while len(P) > 0 and len(R) > 0 and cp < X and cp + cq + cr < XY:
p = -P[0]
r = -R[0]
if p >= r:
score -= heappop(P)
cp += 1
else:
score -= heappop(R)
cr += 1
while len(Q) > 0 and len(R) > 0 and cq < Y and cp + cq + cr < XY:
q = -Q[0]
r = -R[0]
if q >= r:
score -= heappop(Q)
cq += 1
else:
score -= heappop(R)
cr += 1
while cp < X and cp + cq + cr < XY:
if len(P) > 0:
score -= heappop(P)
cp += 1
else:
score -= heappop(R)
cr += 1
while cq < Y and cp + cq + cr < XY:
if len(Q) > 0:
score -= heappop(Q)
cq += 1
else:
score -= heappop(R)
cr += 1
print(score)
main()
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s322781198 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | a, b, c, d, e = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
t = 0
l = l1 + l3
l.sort(reverse=True)
t = t + sum(l[:a])
l4 = l2 + l3
l4.sort(reverse=True)
t = t + sum(l4[:a])
print(t)
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s027339208 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | x, y, a, b, c = (int(i) for i in input().split())
p = sorted([int(i) for i in input().split()])
q = sorted([int(i) for i in input().split()])
r = sorted([int(i) for i in input().split()])
l = sorted(p + q + r)
print(sum(l[a + b + c - x - y :]))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s363374337 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | import sys
input = lambda: sys.stdin.readline().rstrip()
x, y, a, b, c = [int(c) for c in input().split()]
ps = [int(c) for c in input().split()]
qs = [int(c) for c in input().split()]
rs = [int(c) for c in input().split()]
ps.sort(reverse=True)
qs.sort(reverse=True)
rs.sort(reverse=True)
pind = x - 1
qind = y - 1
rind = 0
for i in range(c + 1):
p = ps[pind]
q = qs[qind]
r = rs[rind]
if min(p, q) >= r:
break
if p <= q:
ps[pind] = r
pind -= 1
else:
qs[qind] = r
qind -= 1
rind += 1
if rind >= c:
break
print(sum(ps[:x]) + sum(qs[:y]))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s935586602 | Accepted | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split(" ")]
q = [int(i) for i in input().split(" ")]
r = [int(i) for i in input().split(" ")]
p = sorted(p)
q = sorted(q)
r = sorted(r)
x_ = a - x
y_ = b - y
flag = 0
ans = sum(p[x_:]) + sum(q[y_:])
for i in range(c - 1, -1, -1):
if p[x_] > q[y_]:
if q[y_] < r[i]:
ans += r[i] - q[y_]
y_ += 1
if y_ >= b:
flag = 1
break
else:
break
else:
if p[x_] < r[i]:
ans += r[i] - p[x_]
x_ += 1
if x_ >= a:
flag = 2
break
else:
break
if flag == 1:
for j in range(i - 1, -1, -1):
if x_ >= a:
break
if p[x_] < r[j]:
ans += r[j] - p[x_]
x_ += 1
else:
break
elif flag == 2:
for j in range(i - 1, -1, -1):
if y_ >= b:
break
if q[y_] < r[j]:
ans += r[j] - q[y_]
y_ += 1
else:
break
print(ans)
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s616614436 | Accepted | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | def mangoes(x, y, red, yellow, cc):
red = sorted(red)
red.reverse()
yellow = sorted(yellow)
yellow.reverse()
cc = sorted(cc)
cc.reverse()
red = red[:x]
yellow = yellow[:y]
newa = red + yellow + cc
newa = sorted(newa)
newa.reverse()
ans = sum(newa[: x + y])
return ans
well = input().split(" ")
x = int(well[0])
y = int(well[1])
a = int(well[2])
b = int(well[3])
c = int(well[4])
red = input().split(" ")
red = [int(x) for x in red]
yellow = input().split(" ")
yellow = [int(x) for x in yellow]
cc = input().split(" ")
cc = [int(x) for x in cc]
print(mangoes(x, y, red, yellow, cc))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s056050542 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | import sys
from io import StringIO
import unittest
import copy
# 検索用タグ、バージョンによる相違点(pypy)
def resolve():
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(key=lambda xx: -xx)
q.sort(key=lambda xx: -xx)
r.sort(key=lambda xx: -xx)
# 着色を一切行わない場合の値
# pypy3(2.4.0)ではlist.copy()が未実装。copy をインポートする必要がある。
def_red = copy.copy(p[0:x])
def_grren = copy.copy(q[0:y])
# 無職のリンゴに置換していく・・
redcnt = -1
grncnt = -1
def_red_cnt = len(def_red)
def_grren_cnt = len(def_grren)
for i in range(len(r)):
if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
continue
if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
# 透明のリンゴを緑に着色して、置き換える。
def_grren[grncnt] = r[i]
if grncnt is not -def_grren_cnt:
grncnt - 1
else:
# 透明のリンゴを赤に着色して、置き換える。
def_red[redcnt] = r[i]
if redcnt is not -def_red_cnt:
redcnt - 1
print(sum(def_red) + sum(def_grren))
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """1 2 2 2 1
2 4
5 1
3"""
output = """12"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2 2 2 2 2
8 6
9 1
2 1"""
output = """25"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
output = """74"""
self.assertIO(input, output)
# def test_自作成_1(self):
# input = """1 1 1 1 1
# 10
# 20
# 90"""
# output = """110"""
# self.assertIO(input, output)
# このパターンで「list index out of range」が発生。
# def test_自作成_2(self):
# input = """1 1 1 1 2
# 10
# 20
# 90 110"""
# output = """200"""
# self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s904153436 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | from collections import defaultdict
def main():
X, Y, A, B, C = map(int, input().split())
pA = sorted(map(int, input().split()), reverse=True)
pB = sorted(map(int, input().split()), reverse=True)
pC = sorted(map(int, input().split()), reverse=True)
# dp[red_count][green_count] = (value, red-index, green-index, non-index)
dp = defaultdict(lambda: defaultdict(lambda: (0, 0, 0, 0)))
for i in range(1, max(X, Y) + 1):
ri = i
gi = i - 1
if 0 < ri:
v, r, g, n = dp[ri - 1][gi]
dp[ri][gi] = max(
dp[ri][gi],
(v + pA[r], r + 1, g, n),
(v + pC[n] if n < C else v, r, g, n + 1),
)
if 0 < gi:
v, r, g, n = dp[ri][gi - 1]
dp[ri][gi] = max(
dp[ri][gi],
(v + pB[g], r, g + 1, n),
(v + pC[n] if n < C else v, r, g, n + 1),
)
ri = i - 1
gi = i
if 0 < ri:
v, r, g, n = dp[ri - 1][gi]
dp[ri][gi] = max(
dp[ri][gi],
(v + pA[r], r + 1, g, n),
(v + pC[n] if n < C else v, r, g, n + 1),
)
if 0 < gi:
v, r, g, n = dp[ri][gi - 1]
dp[ri][gi] = max(
dp[ri][gi],
(v + pB[g], r, g + 1, n),
(v + pC[n] if n < C else v, r, g, n + 1),
)
ri = i
gi = i
if 0 < ri:
v, r, g, n = dp[ri - 1][gi]
dp[ri][gi] = max(
dp[ri][gi],
(v + pA[r], r + 1, g, n),
(v + pC[n] if n < C else v, r, g, n + 1),
)
if 0 < gi:
v, r, g, n = dp[ri][gi - 1]
dp[ri][gi] = max(
dp[ri][gi],
(v + pB[g], r, g + 1, n),
(v + pC[n] if n < C else v, r, g, n + 1),
)
print(dp[X][Y][0])
main()
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s495507083 | Accepted | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | x, y, a, b, c = map(int, input().split())
p = list(map(lambda x: ["red", int(x)], input().split()))
q = list(map(lambda x: ["green", int(x)], input().split()))
r = list(map(lambda x: ["nan", int(x)], input().split()))
p.sort(key=lambda x: x[1])
p = p[-x:]
q.sort(key=lambda x: x[1])
q = q[-y:]
p[len(p) : len(p)] = q
p[len(p) : len(p)] = r
p.sort(key=lambda x: x[1])
p = p[-x - y :]
print(sum([pi[1] for pi in p]))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s696076071 | Accepted | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | def main():
import sys
input = sys.stdin.buffer.readline
X, Y, A, B, C = (int(i) for i in input().split())
P = [-int(i) for i in input().split()]
Q = [-int(i) for i in input().split()]
R = [-int(i) for i in input().split()]
from heapq import heapify, heappop
heapify(P)
heapify(Q)
heapify(R)
eatP = 0
eatQ = 0
eatR = 0
ans = 0
while X != eatP and Y != eatQ and eatP + eatQ + eatR < X + Y:
if P and Q and R:
cur = min(P[0], Q[0], R[0])
elif P and Q:
cur = min(P[0], Q[0])
elif Q and R:
cur = min(Q[0], R[0])
elif R and P:
cur = min(R[0], P[0])
elif P:
cur = P[0]
elif Q:
cur = Q[0]
elif R:
cur = R[0]
else:
break
ans -= cur
if R and R[0] == cur:
heappop(R)
eatR += 1
elif P and P[0] == cur:
heappop(P)
eatP += 1
elif Q and Q[0] == cur:
heappop(Q)
eatQ += 1
if eatP + eatQ + eatR == X + Y:
return print(ans)
if X != eatP:
while X != eatP and eatP + eatQ + eatR < X + Y:
if R and P:
cur = min(R[0], P[0])
elif R:
cur = R[0]
elif P:
cur = P[0]
else:
break
ans -= cur
if R and R[0] == cur:
heappop(R)
eatR += 1
elif P and P[0] == cur:
heappop(P)
eatP += 1
elif Y != eatQ:
while Y != eatQ and eatP + eatQ + eatR < X + Y:
if R and Q:
cur = min(R[0], Q[0])
elif R:
cur = R[0]
elif Q:
cur = Q[0]
else:
break
ans -= cur
if R and R[0] == cur:
heappop(R)
eatR += 1
elif Q and Q[0] == cur:
heappop(Q)
eatQ += 1
print(ans)
if __name__ == "__main__":
main()
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s451044672 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | x, y, a, b, c = (int(i_x) for i_x in input().split())
allredapple = input().split()
allgreenapple = input().split()
allnonapple = input().split()
allredapple.sort(reverse=True)
allgreenapple.sort(reverse=True)
allnonapple.sort(reverse=True)
zenalist = allredapple[:x] + allgreenapple[:y]
zenalist.sort(reverse=True)
for i in range(len(allnonapple)):
for k in range(len(zenalist)):
if int(zenalist[k]) < int(allnonapple[i]):
zenalist[k] = allnonapple[i]
break
anser = 0
for i in range(len(zenalist)):
anser += int(zenalist[i])
print(anser)
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s077352877 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | i = list(map(int, input().split()))
red = list(map(int, input().split()))
green = list(map(int, input().split()))
white = list(map(int, input().split()))
list = []
a = 0
b = 0
c = 0
for j in range(i[0]):
a = max(red)
list.append(a)
for j in range(i[1]):
b = max(green)
list.append(b)
for j in range(i[0] + i[1]):
if max(white) > min(list):
list.remove(min(list))
list.append(max(white))
else:
break
print(sum(list))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s762215246 | Runtime Error | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | inp = list(map(int, input().strip().split()))[:5]
x, y, a, b, c = inp[0], inp[1], inp[2], inp[3], inp[4]
list1 = list(map(int, input().strip().split()))[:a]
list2 = list(map(int, input().strip().split()))[:b]
list3 = list(map(int, input().strip().split()))[:c]
sum1 = 0
for i in range(x):
sum1 += max(max(list1), max(list3))
if max(list1) > max(list3):
list1.remove(max(list1))
else:
list3.remove(max(list3))
for i in range(y):
sum1 += max(max(list2), max(list3))
if max(list2) > max(list3):
list2.remove(max(list2))
else:
list3.remove(max(list3))
print(sum1)
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s636673837 | Wrong Answer | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | from heapq import heapify, heappush, heappop
def greenandredapples():
X, Y, A, B, C = list(map(int, input().split()))
RedD = sorted(list(map(int, input().split())))
GreenD = sorted(list(map(int, input().split())))
Colorl = sorted(list(map(int, input().split())))
considered = RedD[-X:] + GreenD[-Y:]
# print(considered)
replacements = len(Colorl)
# print(Colorl)
while replacements >= 0 and len(Colorl) > 0:
heapify(considered)
smallest = heappop(considered)
# print("ffff", smallest)
r = Colorl.pop(0)
# print("gggg", r, Colorl)
if smallest >= r:
heappush(considered, smallest)
break
heappush(considered, r)
# print("ccc", considered)
replacements -= 1
# print(considered)
return sum(considered)
print(greenandredapples())
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
Print the maximum possible sum of the deliciousness of the eaten apples.
* * * | s990579721 | Runtime Error | p02727 | Input is given from Standard Input in the following format:
X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C | N = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
def change(A, C):
for i in range(len(A)):
if A[i] < C[0]:
A[i] = C[0]
del C[0]
return A, C
def solve(N, A, B, C):
X = N[0]
Y = N[1]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
hoge, c = change(A[:X], C)
hoge2, c = change(B[:Y], c)
return sum(hoge) + sum(hoge2)
print(solve(N, A, B, C))
| Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of
deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness
r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will
count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum
of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that
can be achieved when optimally coloring zero or more colorless apples. | [{"input": "1 2 2 2 1\n 2 4\n 5 1\n 3", "output": "12\n \n\nThe maximum possible sum of the deliciousness of the eaten apples can be\nachieved as follows:\n\n * Eat the 2-nd red apple.\n * Eat the 1-st green apple.\n * Paint the 1-st colorless apple green and eat it.\n\n* * *"}, {"input": "2 2 2 2 2\n 8 6\n 9 1\n 2 1", "output": "25\n \n\n* * *"}, {"input": "2 2 4 4 4\n 11 12 13 14\n 21 22 23 24\n 1 2 3 4", "output": "74"}] |
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}.
* * * | s329986556 | Accepted | p03566 | 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 | import math
import numpy as np
import decimal
import collections
import itertools
import sys
import random
# Union-Find
class UnionFind:
def __init__(self, n):
self.n = n
self.par = [-1 for i in range(self.n)]
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
p = self.find(x)
q = self.find(y)
if p == q:
return None
if p > q:
p, q = q, p
self.par[p] += self.par[q]
self.par[q] = p
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.par[self.find(x)]
# 素数関連
def prime_numbers(x):
if x < 2:
return []
prime_numbers = [i for i in range(x)]
prime_numbers[1] = 0
for prime_number in prime_numbers:
if prime_number > math.sqrt(x):
break
if prime_number == 0:
continue
for composite_number in range(2 * prime_number, x, prime_number):
prime_numbers[composite_number] = 0
return [prime_number for prime_number in prime_numbers if prime_number != 0]
def is_prime(x):
if x < 2:
return False
if x == 2 or x == 3 or x == 5:
return True
if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
return False
prime_number = 7
difference = 4
while prime_number <= math.sqrt(x):
if x % prime_number == 0:
return False
prime_number += difference
difference = 6 - difference
return True
# Prime-Factorize
def prime_factorize(n):
res = []
while n % 2 == 0:
res.append(2)
n //= 2
f = 3
while f**2 <= n:
if n % f == 0:
res.append(f)
n //= f
else:
f += 2
if n != 1:
res.append(n)
return res
# nCr
mod = 10**9 + 7
class nCr:
def __init__(self, n):
self.n = n
self.fa = [1] * (self.n + 1)
self.fi = [1] * (self.n + 1)
for i in range(1, self.n + 1):
self.fa[i] = self.fa[i - 1] * i % mod
self.fi[i] = pow(self.fa[i], mod - 2, mod)
def comb(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
# 拡張Euclidの互除法
def extgcd(a, b, d=0):
g = a
if b == 0:
x, y = 1, 0
else:
x, y, g = extgcd(b, a % b)
x, y = y, x - a // b * y
return x, y, g
# BIT
class BinaryIndexedTree:
def __init__(self, n):
self.n = n
self.BIT = [0] * (self.n + 1)
def add(self, i, x):
while i <= self.n:
self.BIT[i] += x
i += i & -i
def query(self, i):
res = 0
while i > 0:
res += self.BIT[i]
i -= i & -i
return res
# Associative Array
class AssociativeArray:
def __init__(self, q):
self.dic = dict()
self.q = q
def solve(self):
for i in range(self.q):
Query = list(map(int, input().split()))
if Query[0] == 0:
x, y, z = Query
self.dic[y] = z
else:
x, y = Query
if y in self.dic:
print(self.dic[y])
else:
print(0)
# Floor Sum
def floor_sum(n, m, a, b):
res = 0
if a >= m:
res += (n - 1) * n * (a // m) // 2
a %= m
if b >= m:
res += n * (b // m)
b %= m
y_max = (a * n + b) // m
x_max = y_max * m - b
if y_max == 0:
return res
res += y_max * (n + (-x_max // a))
res += floor_sum(y_max, a, m, (a - x_max % a) % a)
return res
# Z-Algorithm
def z_algorithm(s):
str_len = len(s)
res = [0] * str_len
res[str_len - 1] = str_len
i, j = 1, 0
while i < str_len:
while i + j < str_len and s[i + j] == s[j]:
j += 1
res[i] = j
if j == 0:
i += 1
continue
k = 1
while i + k < str_len and j > res[k] + k:
res[i + k] = res[k]
k += 1
i += k
j -= k
return res
class Manacher:
def __init__(self, s):
self.s = s
def coustruct(self):
i, j = 0, 0
s_len = len(self.s)
res = [0] * s_len
while i < s_len:
while i - j >= 0 and i + j < s_len and self.s[i - j] == self.s[i + j]:
j += 1
res[i] = j
k = 1
while i - k >= 0 and k + res[i - k] < j:
k += 1
i += k
j -= k
# mod-sqrt
def mod_sqrt(a, p):
if a == 0:
return 0
if p == 2:
return 1
k = (p - 1) // 2
if pow(a, k, p) != 1:
return -1
while True:
n = random.randint(2, p - 1)
r = (n**2 - a) % p
if r == 0:
return n
if pow(r, k, p) == p - 1:
break
k += 1
w, x, y, z = n, 1, 1, 0
while k:
if k % 2:
y, z = w * y + r * x * z, x * y + w * z
w, x = w * w + r * x * x, 2 * w * x
w %= p
x %= p
y %= p
z %= p
k >>= 1
return y
n = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))
s_t = sum(t)
ans = [0]
for i in range(n):
ans[-1] = min(ans[-1], v[i])
for j in range(t[i] * 2):
ans.append(v[i])
ans.pop()
ans.append(0)
for i in range(1, s_t * 2 + 1):
ans[i] = min(ans[i - 1] + 1 / 2, ans[i])
for i in range(1, s_t * 2 + 1)[::-1]:
ans[i - 1] = min(ans[i] + 1 / 2, ans[i - 1])
print(sum(ans) / 2)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s549190989 | Accepted | p03566 | 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 | import numpy as np
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))
MAX_V = [0]
for t, v in zip(T, V):
MAX_V[-1] = min(MAX_V[-1], v)
for _ in range(t * 2):
MAX_V.append(v)
# print(MAX_V)
# print(len(MAX_V))
timelistsize = len(MAX_V)
REAL_V = [0] * timelistsize
# スピードが加速する部分の速度を表現
for i in range(1, timelistsize):
REAL_V[i] = min(REAL_V[i - 1] + 0.5, MAX_V[i])
# 終了位置から同じようにして減速部分の速度を表現
REAL_V[-1] = 0
for i in range(timelistsize - 1, 0, -1):
REAL_V[i - 1] = min(REAL_V[i] + 0.5, REAL_V[i - 1])
# 0.5秒刻みの速度ができているので、0.5を高さ,0.5秒ごとの速度を上辺,下辺とした台形面積を足す
answer = 0
for i in range(timelistsize - 1):
answer += (REAL_V[i] + REAL_V[i + 1]) * 0.5 / 2
print(answer)
"""
tsum=np.sum(t)
print(tsum)
Ruisekit=[t[0]]
for i in range(1,N):
Ruisekit.append(t[i]+Ruisekit[i-1])
print(Ruisekit)
downstart=[]
for i in range(N-1):
if v[i]>v[i+1]:
downstart.append(t[i]-(v[i]-v[i+1]))
print(downstart)
velocity=0
downindex=0
if downstart:
nextdownstarttime=downstart[downindex]
state='up'
upstarttime=0
upstartspeed=0
answer=0
maxspeed=v[0]
maxspeedindex=0
for time in range(1,tsum+1):
if state=='up':
velocity+=1
#print('velocity:',velocity)
#print('time',time)
if state=='down':
velocity-=1
if time==nextdownstarttime:
if state=='plane':
answer+=(time-planestarttime)*speed
state='down'
print(state)
downstarttime=time
downstartspeed=speed
downindex+=1
if downindex<len(downstart):
nextdownstarttime=downstart[downindex]
if time==Ruisekit[maxspeedindex]:
maxspeedindex+=1
if maxspeedindex<len(v):
maxspeed=v[maxspeedindex]
if velocity==maxspeed and state!='plane':
if state=='up':
answer+=(time-upstarttime)*(velocity-upstartspeed)*0.5
answer+=(time-upstarttime)*upstartspeed
if state=='down':
answer+=(time-downstarttime)*(downstartspeed-velocity)*0.5
answer+=(time-downstarttime)*downstartspeed
state='plane'
planestarttime=time
speed=velocity
print(answer,time,maxspeed,velocity,state)
"""
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s384441451 | Runtime Error | p03566 | 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 | N=int(input())
T=[0]+[int(x) for x in str(input()).split()]+[0]
V=[0]+[int(x) for x in str(input()).split()]+[0]
time=0
t=[0]
for i in T:
time+=i
t.append(time)
ans=0
for j in range(0,2*time):
m2=100000000
m1=100000000
t1=j/2
t2=(j+1)/2
print(t1,t2)
for i in range(N+2):
a=t[i]
b=t[i+1]
c=V[i]
if t1<=a:
m1=min(m1,c+(a-t1))
elif t1<=b:
m1=min(m1,c)
else:
m1=min(m1,c+t1-b)
if t2<=a:
m2=min(m2,c+(a-t2))
elif t2<=b:
m2=min(m2,c)
else:
m2=min(m2,c+t2-b)
ans+=0.25*(m1+m2)
print(ans)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s472055270 | Accepted | p03566 | 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 | class ConvexHullTrick:
def __init__(self, xlist, INF=10**18):
xlist = sorted(xlist)
self.comp = {x: k for k, x in enumerate(xlist)}
self.h = (len(xlist) - 1).bit_length()
self.n = 2**self.h
self.ie = (0, INF)
self.inf = INF
self.x = xlist + [INF] * (self.n - len(xlist))
self.tree = [self.ie for _ in range(2 * self.n)]
def val(self, line, x):
a, b = line
return a * x + b
def _add_(self, line, idx, lt, rt):
while True:
mid = (lt + rt) // 2
lx = self.x[lt]
mx = self.x[mid]
rx = self.x[rt - 1]
lu = self.val(line, lx) < self.val(self.tree[idx], lx)
mu = self.val(line, mx) < self.val(self.tree[idx], mx)
ru = self.val(line, rx) < self.val(self.tree[idx], rx)
if lu and ru:
self.tree[idx] = line
return
if not lu and not ru:
return
if mu:
self.tree[idx], line = line, self.tree[idx]
if lu != mu:
rt = mid
idx = 2 * idx
else:
lt = mid
idx = 2 * idx + 1
def add_line(self, line):
self._add_(line, 1, 0, self.n)
def add_seg(self, line, lt, rt):
lidx = self.comp[lt] + self.n
ridx = self.comp[rt] + self.n
lt = self.comp[lt]
rt = self.comp[rt]
size = 1
while ridx - lidx > 0:
if lidx & 1:
self._add_(line, lidx, lt, lt + size)
lidx += 1
lt += size
if ridx & 1:
ridx -= 1
rt -= size
self._add_(line, ridx, rt, rt + size)
lidx >>= 1
ridx >>= 1
size <<= 1
def get_min(self, x):
idx = self.comp[x] + self.n
res = self.inf
while idx:
res = min(res, self.val(self.tree[idx], x))
idx >>= 1
return res
N = int(input())
T = list(map(int, input().split()))
V = [0] + list(map(int, input().split())) + [0]
X = [0]
for i in range(N):
X.append(X[-1] + 2 * T[i])
cht = ConvexHullTrick(range(X[-1] + 2))
for i in range(N):
cht.add_seg((0, 2 * V[i + 1]), X[i], X[i + 1] + 1)
for i in range(N):
cht.add_seg((1, 2 * V[i] - X[i]), X[i], X[-1] + 1)
for i in range(N):
cht.add_seg((-1, 2 * V[i + 2] + X[i + 1]), X[0], X[i + 1] + 1)
D = [0 for _ in range(X[-1] + 1)]
for i in range(X[-1] + 1):
D[i] = cht.get_min(i)
S = 0
for i in range(X[-1]):
S += D[i] * 2 + (D[i + 1] - D[i])
print(S / 8)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s840029986 | Accepted | p03566 | 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 | f = lambda line, x: line[0] * x + line[1]
def _add_line(line, k, l, r):
m = (l + r) // 2
if not data[k]:
data[k] = line
return
lx, mx, rx = X[l], X[m], X[r - 1]
left, mid, right = (
f(line, lx) < f(data[k], lx),
f(line, mx) < f(data[k], mx),
f(line, rx) < f(data[k], rx),
)
if left and right:
data[k] = line
return
if not left and not right:
return
if mid:
data[k], line = line, data[k]
if left != mid:
_add_line(line, 2 * k + 1, l, m)
else:
_add_line(line, 2 * k + 2, m, r)
def add_line(line, a, b):
L, R = a + N0, b + N0
a0, b0 = a, b
sz = 1
while L < R:
if R & 1:
R -= 1
b0 -= sz
_add_line(line, R - 1, b0, b0 + sz)
if L & 1:
_add_line(line, L - 1, a0, a0 + sz)
L += 1
a0 += sz
L >>= 1
R >>= 1
sz <<= 1
def query(k):
x = X[k]
k += N0 - 1
s = 10**18
while k >= 0:
if data[k]:
t = f(data[k], x)
if t < s:
s = t
k = (k - 1) // 2
return s
n, *t = map(int, open(0).read().split())
t, v = t[:n], t[n:]
st = sum(t) * 2
m = a = i = 0
N0 = 2 ** (st).bit_length()
data = [None] * (2 * N0 + 1)
X = list(range(st + 1)) + [10**18] * N0
i = b = 0
add_line((0.5, 0), 0, st + 1)
for u, w in zip(t, v):
u += u + i
add_line((0, w), i, u)
# add_line((1,b-i),i,st)
# add_line((-1,w+u),0,u)
add_line((-0.5, w + i / 2), 0, i + 1)
add_line((0.5, w - u / 2), u, st + 1)
i, b = u, w
add_line((-0.5, st / 2), 0, st + 1)
a = x = 0
for i in range(1, st + 1):
y = query(i)
a += (x + y) / 4
x = y
print(a)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s515622240 | Accepted | p03566 | 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 | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2, N + 1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X // n:
return base_10_to_n_without_0(X // n, n) + [X % n]
return [X % n]
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
def ACC1(l):
N = len(l)
ret = [0] * (N + 1)
for i in range(N):
ret[i + 1] = ret[i] + l[i]
return ret
N = I()
T = IL()
V = IL()
ACCT = ACC1(T)
TALL = sum(T)
Lspeed = [min(i / 2, TALL - i / 2) for i in range(TALL * 2 + 1)]
def f(i, j):
t = i / 2
start = ACCT[j]
end = ACCT[j + 1]
if start <= t <= end:
return V[j]
elif t < start:
return V[j] + (start - t)
else:
return V[j] + (t - end)
for i in range(TALL * 2 + 1):
Lspeed[i] = min(Lspeed[i], min(f(i, j) for j in range(N)))
ans = 0
for i in range(TALL * 2):
ans += Lspeed[i] + Lspeed[i + 1]
print(ans / 4)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s506920497 | Accepted | p03566 | 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 | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n = int(input())
t = list(map(lambda x: int(x) * 2, input().split()))
v = list(map(int, input().split()))
s = [None] * n
tmp = 0
for i in range(n):
tmp += t[i]
s[i] = tmp
s.insert(0, 0)
l1 = [] # (時刻, 速度)
l2 = [(0, 0)] # (時刻, 速度)
for i in range(n):
l1.append((s[i], v[i]))
l2.append((s[i + 1], v[i]))
l1.append((s[-1], 0))
vs = [0] * s[-1]
ind = 0
ind1 = 0
ind2 = 0
prv = 0
for i in range(s[-1]):
while ind + 1 < len(s) and i >= s[ind + 1]:
ind += 1
while ind1 + 1 < len(l1) and i >= l1[ind1 + 1][0]:
ind1 += 1
while ind2 + 1 < len(l2) and i >= l2[ind2 + 1][0]:
ind2 += 1
# print(i, ind, ind1, ind2)
vs[i] = min(
prv + 1,
v[ind],
min((l1[j][1] + (l1[j][0] - i) * 0.5) for j in range(ind1 + 1, len(l1))),
min((l2[j][1] + (i - l2[j][0]) * 0.5) for j in range(ind2 + 1)),
)
prv = vs[i]
vs.append(0)
ans = 0
for i in range(len(vs) - 1):
ans += (vs[i] + vs[i + 1]) / 2
print(ans / 2)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s478310469 | Accepted | p03566 | 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 | n = int(input())
t = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
tTotal = sum(t) * 2
speed = [min(i / 2, (tTotal - i) / 2) for i in range(tTotal + 1)]
# ?
start = 0
end = 0
# iter through segments
for i in range(n):
end += t[i] * 2
for j in range(tTotal + 1):
speed[j] = min(speed[j], v[i] + max(0, -(j - start) / 2, (j - end) / 2))
start = end
print(sum(speed) / 2)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s904428698 | Accepted | p03566 | 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 | from itertools import accumulate as ac
n = int(input()) + 2
t = [0] + list(map(int, input().split())) + [0]
v = [0] + list(map(int, input().split())) + [0]
s = [0] + list(ac(t))
def f(i, x):
if s[i] <= x <= s[i + 1]:
return v[i]
elif x < s[i]:
return v[i] + s[i] - x
else:
return v[i] + x - s[i + 1]
c = float("INF")
for i in range(n):
c = min(c, f(i, 0))
e = 0
for i in range(1, 2 * s[-1] + 1):
i = i / 2
d = float("INF")
for j in range(n):
d = min(d, f(j, i))
e += 0.25 * (c + d)
c = d
print(e)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s481224335 | Wrong Answer | p03566 | 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 | import sys
sys.setrecursionlimit(10**9)
def mi():
return map(int, input().split())
def ii():
return int(input())
def isp():
return input().split()
def deb(text):
print("-------\n{}\n-------".format(text))
INF = 10**20
def main():
N = ii()
T = list(mi())
V = list(mi())
if N == 1:
t, v = T[0], V[0]
ans = (t - v) * v
if ans < 0:
ans = t**2 / 4
print(ans)
exit()
acce_areas = 0
pre_v = 0
for i in range(N):
v = V[i]
acce_areas += (v + pre_v) * abs(v - pre_v) / 2
pre_v = v
V.append(0)
T.append(0)
pre_v = 0
rect_sums = 0
for i in range(N):
v, t = V[i], T[i]
next_v = V[i + 1]
dv1 = abs(v - pre_v)
dv2 = abs(next_v - v)
lu = pre_v < v
ld = not lu
ru = v < next_v
rd = not ru
bottom = 0
if lu and rd:
bottom += t - (dv1 + dv2)
if ld and ru:
bottom += t
if lu and ru:
bottom += t - dv1
if ld and rd:
bottom += t - dv2
rect_sums += bottom * v
pre_v = v
ans = acce_areas + rect_sums + V[-2] ** 2 / 2
print(ans)
# ans = 0
# pre_v = 0
# pre_is_up = True
# for i in range(N-1):
# up = V[i] < V[i+1]
# t,v = T[i],V[i]
# acce_area = (v+pre_v) * abs(v-pre_v) / 2
# if up:
# rect_area = (t-abs(v-pre_v))*v
# else:
# rect_area = (t-abs(v-pre_v) - abs(V[i+1]-v))*v
# if
# ans += acce_area + rect_area
# pre_v = v
# pre_is_up = up
# acce_area = (v+pre_v) * abs(v-pre_v) / 2
# rect_area = (t-abs(v-pre_v) - v)*v
# trig_area = v**2 / 2
# ans += acce_area + rect_area + trig_area
if __name__ == "__main__":
main()
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s659164681 | Accepted | p03566 | 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 | from bisect import bisect_left, bisect_right
from itertools import accumulate
N = int(input())
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))
Ts = list(accumulate([0] + ts))
# 横向きにカットするイメージ
def solve(begin, end, v):
# print(' ' * v, begin, end, v, vs[bisect_right(Ts, begin) - 1:bisect_left(Ts, end)])
if begin >= end:
return 0
if begin + 1 == end:
if v < vs[bisect_right(Ts, begin) - 1]:
return 0.25
else:
return 0
min_v = min(vs[bisect_right(Ts, begin) - 1 : bisect_left(Ts, end)])
if min_v == v:
ret = 0
last = begin
for i in range(bisect_right(Ts, begin) - 1, bisect_left(Ts, end)):
if v == vs[i]:
ret += solve(last, Ts[i], v)
last = Ts[i + 1]
ret += solve(last, end, v)
return ret
else:
return end - begin - 1 + solve(begin + 1, end - 1, v + 1)
print(solve(0, Ts[-1], 0))
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s848546008 | Accepted | p03566 | 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 | N = int(input())
(*T,) = map(int, input().split())
(*V,) = map(int, input().split())
speed = [0] # speed[i]: speed of train after 0.5*i seconds
for t, v in zip(T, V):
speed[-1] = min(speed[-1], v)
speed += [v] * (2 * t)
speed[-1] = 0
temp = 0
for t in range(1, len(speed)):
speed[t] = temp = min(speed[t], temp + 0.5)
temp = 0
for t in range(len(speed) - 1, 0, -1):
speed[t] = temp = min(speed[t], temp + 0.5)
ans = sum((v1 + v2) / 4 for v1, v2 in zip(speed, speed[1:]))
print(ans)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s632405040 | Accepted | p03566 | 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 | from collections import deque
def main():
with open(0) as f:
N, *Temp = map(int, f.read().split())
T, V = Temp[:N], Temp[N:]
del Temp
# v-tグラフを仮定して、各区間の境界条件を求める
v_left = deque([0]) # 初期時刻から走査した結果
v_right = deque([0]) # 終了時刻から走査した結果
# 区間i(1<=i<=N)の境界条件は [min(vin[i-1], vout[i-1]), max(vin[i], vout[i])
# 走査処理
now = 0
for t, v in zip(T, V):
now = min(now + t, v)
v_left.append(now)
now = 0
for t, v in zip(reversed(T), reversed(V)):
now = min(now + t, v)
v_right.appendleft(now)
BC = [min(x, y) for x, y in zip(v_left, v_right)] # 境界条件
# 区間ごとに2倍の面積計算
S = [
squareMeasure(vin, vout, vsup, t)
for vin, vout, vsup, t in zip(BC[:N], BC[1:], V, T)
]
ans = sum(S) / 2
print(ans)
def squareMeasure(vin, vout, vsup, t):
vmax = (t + vout + vin) / 2 # y=x+vinとy=-x+t+vout の交点のy
if vmax > vsup:
a, b = vsup - vin, t + vout - vsup # y=vsupと2直線の交点
S = (vin + vsup) * a + 2 * (b - a) * vsup + (vsup + vout) * (t - b)
else:
S = (vin + vmax) * (vmax - vin) + (vmax + vout) * (t + vin - vmax)
return S # 2倍の面積である
if __name__ == "__main__":
main()
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s889830279 | Accepted | p03566 | 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 | #!/usr/bin/env python
# coding: utf-8
def ri():
return int(input())
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def mileage(t, v, vl, vr):
assert 0 <= vl <= v and 0 <= vr <= v
# 最高速度v, 左端での速度vl, 右端での速度vr, 秒数tの時の走行距離を求める
l = v - vl
r = t - (v - vr)
if l > r:
tmp = (l + r) / 2
l = tmp
r = tmp
ret = 0
ret += l * l / 2 + vl * l
ret += (r - l) * v
ret += (t - r) * vr + (t - r) * (t - r) / 2
return ret
def main():
n = ri()
lt = rli()
lv = rli()
lt.append(0)
lv.append(0)
lefts = [0] # 各区間の左端での列車の速度
for i in range(n):
left = min(lefts[i] + lt[i], lv[i], lv[i + 1])
offset = 0
for j in range(i + 1, n + 1):
left = min(left, offset + lv[j])
offset += lt[j]
lefts.append(left)
# print(lefts)
ans = 0
for i in range(n):
ans += mileage(lt[i], lv[i], lefts[i], lefts[i + 1])
print(ans)
if __name__ == "__main__":
main()
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s076071681 | Runtime Error | p03566 | 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 | def solve(t1, v1, t2, v2, vmax):
if v1 > vmax or v2 > vmax:
return -inf
if t2 - t1 < abs(v2 - v1):
return -inf
vmax_theory = min(v1, v2) + ((t2 - t1) + abs(v2 - v1)) / 2.0
area1 = (vmax_theory - min(v1, v2)) ** 2
area2 = (abs(v1 - v2)) ** 2 / 2.0
area3 = (t2 - t1) * min(v1, v2)
if vmax_theory < vmax:
return area1 - area2 + area3
else:
area4 = (vmax_theory - vmax) ** 2
return area1 - area2 + area3 - area4
N = int(input())
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))
ts = [0] + ts
vs = [0] + vs
from itertools import accumulate
ts = list(accumulate(ts))
inf = 1000000007
dp = [[-inf for x in range(205)] for y in range(len(ts))]
t_idx = 0
t_tot = sum(ts)
for t_idx in range(len(ts)):
if t_idx == 0:
dp[t_idx][0] = 0.0
else:
for v1 in range(vs[t_idx - 1] + 1):
for v2 in range(vs[t_idx] + 1):
if dp[t_idx - 1][v1] < 0 or abs(v2 - v1) > ts[t_idx] - ts[t_idx - 1]:
continue
dp[t_idx][v2] = max(
dp[t_idx][v2],
dp[t_idx - 1][v1]
+ solve(ts[t_idx - 1], v1, ts[t_idx], v2, vs[t_idx]),
)
print("{:.12f}".format(dp[len(ts) - 1][0]))
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s477132438 | Runtime Error | p03566 | 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 | n = int(input())
t = [None] + list(map(int, input().split())) + [None]
v = [0] + list(map(int, input().split())) + [0]
distance = 0
for i in range(1, n + 1):
former_speed = v[i - 1]
current_speed = v[i]
next_speed = v[i + 1]
if current_speed >= next_speed:
end = current_speed - next_speed
if former_speed >= current_speed:
start = 0
else:
start = current_speed - former_speed
stay = t[i] - (start + end)
else:
end = 0
if former_speed >= current_speed:
start = 0
else:
start = current_speed - former_speed
stay = t[i] - (start + end)
if stay >= 0:
delta = (
0.5 * (former_speed + current_speed) * start
+ current_speed * stay
+ 0.5 * (next_speed + current_speed) * end
)
else:
if end >= t[i]:
delta = 0.5 * (former_speed + next_speed) * t[i]
else:
diff = next_speed - former_speed
end = 0.5 * (diff + t[i])
start = t[i] - end
current_speed = former_speed + start
delta *= (
0.5 * (former_speed + current_speed) * start
+ 0.5 * (next_speed + current_speed) * end
)
distance += delta
print(distance)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s288338842 | Accepted | p03566 | 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 | def solve(N, T, V):
from itertools import accumulate
ds = [0] + list(accumulate(T))
vs = [0] + [min(V[i], V[i + 1]) for i in range(len(V) - 1)] + [0]
for i in range(len(vs)):
d = ds[i]
vs[i] = min([v + abs(d - ds[j]) for j, v in enumerate(vs)])
def calc(t, v0, v1, maxv):
t0 = maxv - v0
t1 = maxv - v1
if t0 + t1 < t:
return t * maxv - t0 * t0 / 2 - t1 * t1 / 2
else:
t0 = (t + v1 - v0) / 2
t1 = (t + v0 - v1) / 2
v = (t + v0 + v1) / 2
S = v * t - t0 * t0 / 2 - t1 * t1 / 2
return S
r = 0
for i in range(N):
c = calc(T[i], vs[i], vs[i + 1], V[i])
r += c
return r
if __name__ == "__main__":
N = int(input())
T = [int(_) for _ in input().split()]
V = [int(_) for _ in input().split()]
print(solve(N, T, V))
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s046000333 | Accepted | p03566 | 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 | N = int(input())
T = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]
T.append(0)
V.append(0)
Vt = [0 for i in range(N + 1)]
r = sum(T)
R = [0 for i in range(N)]
for i in range(N - 1):
r -= T[i]
R[i] = r
for i in range(N - 1, -1, -1):
Vt[i] = min(V[i], V[i + 1], Vt[i + 1] + T[i + 1])
L = 0
v0 = 0
for i in range(N):
ta = min(V[i] - v0, (T[i] - (v0 - Vt[i])) / 2, T[i])
tb = max(v0 + ta - Vt[i], 0)
L += (
(2 * v0 + ta) * ta / 2
+ (v0 + ta) * (T[i] - ta - tb)
+ (2 * (v0 + ta) - tb) * tb / 2
)
v0 = v0 + ta - tb
print(L)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s262512965 | Runtime Error | p03566 | 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 | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
if n==1:
if a[0]>=b[0]*2:
print(b[0]**2+b[0]*(a[0]-b[0]*2))
else:
print(a[0]/2**2)
else:
for i in range(n):
if i==n-1:
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s853417466 | Runtime Error | p03566 | 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 | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
if n==1:
if a[0]>=b[0]*2:
print(b[0]**2+b[0]*(a[0]-b[0]*2))
else:
print(a[0]/2**2)
else:
for i in range(n):
if i==n-1:
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s088273567 | Runtime Error | p03566 | 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 | 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:
if v==v_p:
ans+=t_p*v_p
v=v_a
elif v_a-v>=t_p:
ans+=
v=v_a
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=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) | 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s296902137 | Accepted | p03566 | 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 | # --*-coding:utf-8-*--
def f(n, ts, vs):
sumOfT = sum(ts)
t = 0
k = 0
k1s = [k]
for i in range(n - 1):
t += ts[i]
k = min(k, vs[i] - t)
k1s.append(k)
t = sumOfT
k = t
k2s = [k]
for i in range(n - 1, 0, -1):
t -= ts[i]
k = min(k, vs[i] + t)
k2s.insert(0, k)
t0 = 0
d = 0
for t, v, k1, k2 in zip(ts, vs, k1s, k2s):
# t0 制限速度がv である開始時刻
# t1 加速を終わらせる時刻
# t2 減速を始める時刻
# t3 制限速度がv である終了時刻
t3 = t0 + t
t1 = v - k1
t2 = k2 - v
if t1 > t2:
t1 = (k2 - k1) / 2
t2 = t1
if t0 < t1:
t12 = min(t1, t3)
d += k1 * (t12 - t0) + (t12**2 - t0**2) / 2
dt = min(t2, t3) - max(t0, t1)
if dt > 0:
d += v * dt
if t2 < t3:
t22 = max(t2, t0)
d += k2 * (t3 - t22) - (t3**2 - t22**2) / 2
t0 = t3
return d
def test():
assert f(1, [100], [30]) == 2100
assert f(2, [60, 50], [34, 38]) == 2632
assert f(3, [12, 14, 2], [6, 2, 7]) == 76
assert f(1, [9], [10]) == 20.25
assert (
f(
10,
[64, 55, 27, 35, 76, 119, 7, 18, 49, 100],
[29, 19, 31, 39, 27, 48, 41, 87, 55, 70],
)
== 20291
)
def main():
n = int(input())
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))
print("{0:.4f}".format(f(n, ts, vs)))
if __name__ == "__main__":
main()
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s496142724 | Wrong Answer | p03566 | 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 | N = int(input())
T = [int(x) for x in str(input()).split()]
V = [int(x) for x in str(input()).split()] + [0]
dist = 0
speed = 0
for i in range(N):
# print(speed,T[i],V[i],V[i+1])
if V[i] >= speed:
if V[i] <= V[i + 1]:
if T[i] >= V[i] - speed:
dist += speed * (V[i] - speed) + 0.5 * (V[i] - speed) ** 2
dist += V[i] * (T[i] - (V[i] - speed))
speed = V[i]
else:
dist += speed * (T[i]) + 0.5 * (T[i]) ** 2
speed += T[i]
else:
# print("123")
if T[i] >= V[i] - speed + V[i] - V[i + 1]:
# print("Hello")
dist += speed * (V[i] - speed) + 0.5 * (V[i] - speed) ** 2
dist += V[i] * (T[i] - (V[i] - speed + V[i] - V[i + 1]))
dist += V[i] * (V[i] - V[i + 1]) - 0.5 * (V[i] - V[i + 1]) ** 2
speed = V[i]
else:
# print("23")
if speed >= V[i + 1]:
if T[i] - (speed - V[i + 1]) > 0:
t = 0.5 * (T[i] - (speed - V[i + 1]))
dist += speed * t + 0.5 * (t) ** 2
dist += (speed + t) * (T[i] - t) - 0.5 * (T[i] - t) ** 2
speed = V[i + 1]
# print("HE")
else:
# print("XY")
if speed - V[i + 1] - T[i] <= T[i - 1]:
t = speed - V[i + 1]
dist -= speed * (t - T[i])
dist += speed * t - 0.5 * (t) ** 2
else:
t = speed - V[i + 1]
dist -= speed * (t - T[i])
dist += speed * t - 0.5 * (t) ** 2
else:
if T[i] - (V[i + 1] - speed) > 0:
# print("xt")
t = 0.5 * (T[i] - (V[i + 1] - speed))
dist += speed * (T[i] - t) + 0.5 * (T[i] - t) ** 2
dist += (speed + T[i] - t) * (t) - 0.5 * (t) ** 2
speed = V[i + 1]
else:
# print("XY")
t = V[i + 1] - speed
dist -= speed * t
dist += speed * t - 0.5 * (t) ** 2
else:
if V[i] <= V[i + 1]:
dist += V[i] * T[i]
speed = V[i]
else:
dist += V[i] * (T[i] - (V[i] - V[i + 1]))
dist += V[i] * (V[i] - V[i + 1]) - 0.5 * (V[i] - V[i + 1]) ** 2
speed = V[i + 1]
# print(dist)
print(dist)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s645313559 | Wrong Answer | p03566 | 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 | import itertools
n = int(input())
time = list(map(int, input().split()))
timetable = list(itertools.accumulate([0] + time))
v_max = list(map(int, input().split()))
dt = 0.5
v_table = [
i * 0.5 if i < sum(time) else (sum(time) * 2 - i) * 0.5
for i in range(sum(time) * 2)
]
for i in range(n):
t_s, t_e = timetable[i], timetable[i + 1]
for j in range(len(v_table)):
if j * dt < t_s:
v = v_max[i] + (t_s - j * dt)
elif t_s <= j * dt <= t_e:
v = v_max[i]
else:
v = v_max[i] + (j * dt - t_e)
v_table[j] = min(v_table[j], v)
print(int(sum(v_table) * dt))
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s574398965 | Wrong Answer | p03566 | 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 | num = int(input())
in1 = input().split(" ")
in2 = input().split(" ")
times = [0]
ct = 0
for a in range(num):
in1[a] = int(in1[a])
in2[a] = int(in2[a])
for a in range(num):
ct += in1[a]
times.append(ct)
vlimit = []
for a in range(1, num):
vlimit.append(min(in2[a - 1], in2[a]))
vlimit.append(in2[num - 1])
print(in1, in2)
print(times, vlimit)
bairitu = 300
last = times[len(times) - 1]
limit = [0 for a in range(last * bairitu + 1)]
for a in range(last * bairitu):
limit[a] = round(min(a / bairitu, last - a / bairitu), 2)
for a in range(len(vlimit)):
start = times[a] * bairitu
end = times[a + 1] * bairitu
for b in range(start, end):
limit[b] = min(limit[b], in2[a])
# print(str(limit))
for a in range(len(vlimit)):
for b in range(0, times[a + 1] * bairitu):
limit[b] = min(limit[b], times[a + 1] - b / bairitu + vlimit[a])
for b in range(times[a + 1] * bairitu + 1, last * bairitu + 1):
limit[b] = min(limit[b], b / bairitu - times[a + 1] + vlimit[a])
ans = 0
for a in range(1, len(limit)):
ans += (limit[a] + limit[a - 1]) / bairitu / 2
print(ans)
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s460899177 | Wrong Answer | p03566 | 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 | N = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))
if N == 1: # 最初の1区間だけ
if t[0] % 2 == 1: # 奇数秒
if t[0] / 2 < v[0]:
print((t[0] / 2) ** 2)
exit()
# print ('t', t)
# print ('v', v)
N_INF = -(10**9)
DP = [
[N_INF] * (102) for _ in range(100 * 200 + 2)
] # DP[T][V] := 時刻Tに速度Dで走っているときの時刻Tまでの走行距離の最大値
DP[0][0] = 0
# print (DP[0][0:5])
time = 1
for i in range(N):
# print (i)
# print ('time', time)
for j in range(time, time + t[i]): # 時刻
# print (j, end = ' ')
for k in range(0, v[i] + 1): # 速度
if k == 0:
# print (j, k)
# print (max(DP[j - 1][0], DP[j - 1][1] + 1/2))
DP[j][k] = max(DP[j - 1][0], DP[j - 1][1] + 1 / 2)
elif k != v[i]:
DP[j][k] = max(
DP[j - 1][k - 1] + k - 1 / 2,
DP[j - 1][k] + k,
DP[j - 1][k + 1] + k + 1 / 2,
)
else: # (k == v[i] and j != time)
DP[j][k] = max(DP[j - 1][k - 1] + k - 1 / 2, DP[j - 1][k] + k)
# print (DP[j][0:5])
time += t[i]
# print (time)
print(DP[time - 1][0])
# print ('T = 6, V = 6', DP[6][6])
# print ('T = 12, V = 2', DP[12][2])
# print ('T = 12, V = 3', DP[12][3])
# print ('T = 13, V = 2', DP[13][2])
# print ('T = 26 V = 2', DP[26][2])
# print ('T = 27 V = 2', DP[27][2])
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s542984989 | Accepted | p03566 | 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 | N = int(input())
tli = [int(it) * 2 for it in input().split()]
vli = [int(it) * 2 for it in input().split()]
vmax = [0]
for i in range(len(tli)):
tmp = vmax.pop()
vmax.append(min(tmp, vli[i]))
vmax.extend([vli[i]] * (tli[i]))
vmax[-1] = 0
vmax[0] = 0
T = len(vmax) - 1
for j in range(1000):
for i in range(T):
vmax[i + 1] = min(vmax[i] + 1, vmax[i + 1])
for i in range(T, 0, -1):
vmax[i - 1] = min(vmax[i] + 1, vmax[i - 1])
if j == 0:
pass
# print ( vmax )
print(0.25 * sum(vmax))
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
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}.
* * * | s732539347 | Wrong Answer | p03566 | 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 | n = int(input())
t = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
v_real = [v[i] for i in range(n) for j in range(t[i])]
v_real.append(0)
v_real.insert(0, 0)
def acc(v):
for i in range(len(v) - 1):
if not -1 <= v[i + 1] - v[i] and v[i + 1] - v[i] <= 1:
return False
return True
def update(v):
for i in range(len(v) - 1):
if v[i + 1] - v[i] > 1:
v[i + 1] = v[i] + 1
elif v[i + 1] - v[i] < -1:
v[i] = v[i + 1] + 1
return v
def calc(v):
acc = []
dis = 0
for i in range(len(v) - 1):
if v[i + 1] - v[i] == 1:
acc.append(1)
elif v[i + 1] == v[i]:
acc.append(0)
else:
acc.append(-1)
for i in range(len(v) - 1):
dis += v[i] + 1.0 / 2 * acc[i]
return dis
while not acc(v_real):
v_real = update(v_real)
print(calc(v_real))
| 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. | [{"input": "1\n 100\n 30", "output": "2100.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.\n * In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.\n * In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.\n\nThe total distance covered is 450 \\+ 1200 \\+ 450 = 2100 meters.\n\n* * *"}, {"input": "2\n 60 50\n 34 38", "output": "2632.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 34 seconds, it accelerates at a rate of 1m/s^2, covering 578 meters.\n * In the subsequent 26 seconds, it maintains the velocity of 34m/s, covering 884 meters.\n * In the subsequent 4 seconds, it accelerates at a rate of 1m/s^2, covering 144 meters.\n * In the subsequent 8 seconds, it maintains the velocity of 38m/s, covering 304 meters.\n * In the last 38 seconds, it decelerates at the acceleration of -1m/s^2, covering 722 meters.\n\nThe total distance covered is 578 \\+ 884 \\+ 144 \\+ 304 \\+ 722 = 2632 meters.\n\n* * *"}, {"input": "3\n 12 14 2\n 6 2 7", "output": "76.000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 6 seconds, it accelerates at a rate of 1m/s^2, covering 18 meters.\n * In the subsequent 2 seconds, it maintains the velocity of 6m/s, covering 12 meters.\n * In the subsequent 4 seconds, it decelerates at the acceleration of -1m/s^2, covering 16 meters.\n * In the subsequent 14 seconds, it maintains the velocity of 2m/s, covering 28 meters.\n * In the last 2 seconds, it decelerates at the acceleration of -1m/s^2, covering 2 meters.\n\nThe total distance covered is 18 \\+ 12 \\+ 16 \\+ 28 \\+ 2 = 76 meters.\n\n* * *"}, {"input": "1\n 9\n 10", "output": "20.250000000000000000\n \n\n\n\nThe maximum distance is achieved when a train runs as follows:\n\n * In the first 4.5 seconds, it accelerates at a rate of 1m/s^2, covering 10.125 meters.\n * In the last 4.5 seconds, it decelerates at the acceleration of -1m/s^2, covering 10.125 meters.\n\nThe total distance covered is 10.125 \\+ 10.125 = 20.25 meters.\n\n* * *"}, {"input": "10\n 64 55 27 35 76 119 7 18 49 100\n 29 19 31 39 27 48 41 87 55 70", "output": "20291.000000000000"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s413760212 | Accepted | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in sys.stdin.readline().split()]
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
def gcd_list(L):
v = L[0]
for i in range(1, len(L)):
v = gcd(v, L[i])
return v
def lcm(n, m):
return (n * m) // gcd(n, m)
def lcm_list(L):
v = L[0]
for i in range(1, len(L)):
v = lcm(v, L[i])
return v
# Width First Search (+ Distance)
def wfs_d(D, N, K):
"""
D: 隣接行列(距離付き)
N: ノード数
K: 始点ノード
"""
dfk = [-1] * (N + 1)
dfk[K] = 0
cps = [(K, 0)]
r = [False] * (N + 1)
r[K] = True
while len(cps) != 0:
n_cps = []
for cp, cd in cps:
for i, dfcp in enumerate(D[cp]):
if dfcp != -1 and not r[i]:
dfk[i] = cd + dfcp
n_cps.append((i, cd + dfcp))
r[i] = True
cps = n_cps[:]
return dfk
# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
"""
v: 現在のノード
pre: 1つ前のノード
dist: 現在の距離
以下は別途用意する
D: 隣接リスト(行列ではない)
D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト
"""
global D
global D_dfs_d
D_dfs_d[v] = dist
for next_v, d in D[v]:
if next_v != pre:
dfs_d(next_v, v, dist + d)
return
def sigma(N):
ans = 0
for i in range(1, N + 1):
ans += i
return ans
def comb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def bisearch(L, target):
low = 0
high = len(L) - 1
while low <= high:
mid = (low + high) // 2
guess = L[mid]
if guess == target:
return True
elif guess < target:
low = mid + 1
elif guess > target:
high = mid - 1
if guess != target:
return False
# --------------------------------------------
dp = None
def main():
N = int(input())
L = li_input()
x = max(L)
i = L.index(x)
L_ = L[:i] + L[i + 1 :]
if x < sum(L_):
print("Yes")
else:
print("No")
main()
| Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s150542739 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def inputI():
return int(input().strip())
def inputS():
return input().strip()
def inputIL():
return list(map(int, input().split()))
def inputSL():
return list(map(str, input().split()))
def inputILs(n):
return list(int(input()) for _ in range(n))
def inputSLs(n):
return list(input().strip() for _ in range(n))
def inputILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def Yes():
print("Yes")
def No():
print("No")
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#############
# Main Code #
#############
N = inputI()
l = inputIL()
l.sort()
if sum(l[:-1]) >= sum[l]:
No()
else:
Yes()
| Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s674659395 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9+7
INF = float('inf')
#############
# Functions #
#############
######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def Yes(): print("Yes") return
def No(): print("No") return
#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n):
return kaijo_memo[n]
if(len(kaijo_memo) == 0):
kaijo_memo.append(1)
while(len(kaijo_memo) <= n):
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n):
return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0):
gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n):
gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if(n == r):
return 1
if(n < r or r < 0):
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
#####LCM#####
def lcm(a, b):
return a * b // gcd (a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n -1
count += 1
return count
#############
# Main Code #
#############
N = inputI()
l = inputIL()
l.sort()
if sum(l[:-1]) >= sum[l]:
No()
else:
Yes()
| Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s766082171 | Wrong Answer | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | # abc117_b.py
# https://atcoder.jp/contests/abc117/tasks/abc117_b
# B - Polygon /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点
# 問題文
# 2次元平面上に辺の長さがそれぞれ L1,L2,...,LN の N角形(凸多角形でなくてもよい)が描けるかを判定してください。
# ここで、次の定理を利用しても構いません。
# 定理 : 一番長い辺が他の N−1辺の長さの合計よりも真に短い場合に限り、条件を満たす N角形が描ける。
# 制約
# 入力は全て整数である。
# 3≤N≤10
# 1≤Li≤100
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# L1 L2 ... LN
# 出力
# 条件を満たす N角形が描けるなら Yes、そうでないなら No を出力せよ。
# 入力例 1
# 4
# 3 8 5 1
# 出力例 1
# Yes
# 8<9=3+5+1なので、定理より 2 次元平面上に条件を満たす N角形が描けます。
# 入力例 2
# 4
# 3 8 4 1
# 出力例 2
# No
# 8≥8=3+4+1なので、定理より 2 次元平面上に条件を満たす N角形は描けません。
# 入力例 3
# 10
# 1 8 10 5 8 12 34 100 11 3
# 出力例 3
# No
def calculation(lines):
N = lines[0]
# N = int(lines[0])
values = list(map(int, lines[1].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i+1]))
ma = max(values)
su = sum(values)
if ma * 2 < su:
result = "Yes"
else:
result = "No"
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ["4", "3 8 5 1"]
lines_export = ["Yes"]
if pattern == 2:
lines_input = ["4", "3 8 4 1"]
lines_export = ["No"]
if pattern == 3:
lines_input = ["10", "1 8 10 5 8 12 34 100 11 3"]
lines_export = ["No"]
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
if len(args) == 1:
mode = 0
else:
mode = int(args[1])
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(2)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
if mode > 0:
print(f"lines_input=[{lines_input}]")
print(f"lines_export=[{lines_export}]")
print(f"lines_result=[{lines_result}]")
if lines_result == lines_export:
print("OK")
else:
print("NG")
finished = time.time()
duration = finished - started
print(f"duration=[{duration}]")
# 起動処理
if __name__ == "__main__":
main()
| Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s647823986 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | S = int(input())
L = list(map(int, input().sprit()))
print("Yes" if sum(L) > max(L) * 2 else "No")
| Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s477327713 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | n = int(input())
x = list(map(int, input().split()))
x.sort()
print("Yes" if x[-1] < sum(x[:-1] else "No") | Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s827633234 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | n = list(input())
s_L = list(map(int,input().split())
s_L = sorted(s_L,reverse=True)
if s_L[0] < sum(s_L[1:]):
print("Yes")
else:
print("No") | Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s106071191 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | n=int(input())
l=sorted(list(map(int,input().split()))reverse=True)
if l[0]<sum(l[1:]):
print("Yes")
else:
print("No") | Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s016941345 | Accepted | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | _, a = input(), sorted(list(map(int, input().split())))
print("Yes" if sum(a[0:-1]) > a[-1] else "No")
| Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s900627759 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | 10
1 8 10 5 8 12 34 100 11 3 | Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s257697921 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | n = input()
a = list(map(int, input().split()))
if max(a) >= sum(a) - max(a):
print("Yes")
else:
print("No") | Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s183656631 | Accepted | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | n = int(input())
List = [int(i) for i in input().split()]
a = max(List) # sortよりmaxとsumのほうが楽
b = sum(List)
print("Yes" if a < b - a else "No") # 1行で書ける
| Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
If an N-sided polygon satisfying the condition can be drawn, print `Yes`;
otherwise, print `No`.
* * * | s842398656 | Runtime Error | p03136 | Input is given from Standard Input in the following format:
N
L_1 L_2 ... L_N | a= input()
b = input().split()
s = 0
for i in range(0,len(b)):
s+=int(b[i])
if s-max(b)>max(b):
print("Yes")
else:
print("No) | Statement
Determine if an N-sided polygon (not necessarily convex) with sides of length
L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
**Theorem** : an N-sided polygon satisfying the condition can be drawn if and
only if the longest side is strictly shorter than the sum of the lengths of
the other N-1 sides. | [{"input": "4\n 3 8 5 1", "output": "Yes\n \n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can\nbe drawn on a plane.\n\n* * *"}, {"input": "4\n 3 8 4 1", "output": "No\n \n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon\ncannot be drawn on a plane.\n\n* * *"}, {"input": "10\n 1 8 10 5 8 12 34 100 11 3", "output": "No"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.