| Task: | Roller coaster |
| Sender: | aalto26hw_007 |
| Submission time: | 2026-10-28 17:34:07 +0200 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.07 s | details |
| #2 | ACCEPTED | 0.08 s | details |
| #3 | ACCEPTED | 0.08 s | details |
| #4 | ACCEPTED | 0.07 s | details |
| #5 | ACCEPTED | 0.07 s | details |
| #6 | ACCEPTED | 0.08 s | details |
| #7 | ACCEPTED | 0.07 s | details |
| #8 | ACCEPTED | 0.08 s | details |
| #9 | ACCEPTED | 0.08 s | details |
| #10 | ACCEPTED | 0.07 s | details |
| #11 | ACCEPTED | 0.07 s | details |
| #12 | ACCEPTED | 0.08 s | details |
Code
import sys
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate, groupby
from functools import lru_cache, cmp_to_key, reduce
from math import gcd, isqrt, comb, inf, pi, sqrt, atan2, hypot, ceil
from fractions import Fraction
def main():
data = sys.stdin.buffer.read().split(); idx = 0
n = int(data[idx]); idx += 1
# n, m = map(int, data[idx:idx + 2]); idx += 2
# a = list(map(int, data[idx:idx + n])); idx += n
# s = data[idx].decode(); idx += 1 # strings
P = []
R = []
A = []
F = []
for _ in range(n):
a, b, c, d = map(int, data[idx:idx + 4]); idx += 4
P.append(a)
R.append(b)
A.append(c)
F.append(d)
# g = [data[idx + i].decode() for i in range(n)]; idx += n # grid of n rows, no spaces, strings
# input = sys.stdin.readline
# n, m = map(int, input().split())
# s = input().strip() # strip removes the trailing newline
# for line in sys.stdin: # read until EOF
# out = []
# def fn(s):
# not_happy = 0
# for i in range(n):
# if s < R[i]:
# return 0
# return i
# if s < P[i]:
# not_happy += 1
# s = s*(1-F[i]/100) - A[i]
# # if s < 0:
# # return 0
# if not_happy >= (n+1) // 2:
# # return 50 + not_happy
# return 0
# return 100
# # l = list(range(10000000))
# # idx = bisect_left(l, 99, key=fn)
# # print(idx)
# def bl(f, target, lo, hi):
# while lo < hi:
# mid = lo + (hi - lo) // 2
# if f(mid) < target:
# lo = mid + 1
# else:
# hi = mid
# return lo
# print(bl(fn, 99, 0, 10**100))
# for i in range(2010101010100993900150785-1, 2010101010100993900150785 +2):
# print(i, fn(i))
# print("not found")
# return -1
happy_when_more_than = []
min_speed = R[n-1]
for i in range(n-1, -1, -1):
if i == n-1:
min_speed = R[n-1]
else:
# min_speed = (min_speed + A[i]) / (1-F[i]/100)
min_speed = (min_speed + A[i]) * Fraction(100, 100 - F[i])
min_speed = max(min_speed, R[i])
for j in range(len(happy_when_more_than)):
# happy_when_more_than[j] = (happy_when_more_than[j] + A[i]) / (1-F[i]/100)
happy_when_more_than[j] = (happy_when_more_than[j] + A[i]) * Fraction(100, 100 - F[i])
happy_when_more_than.append(P[i])
# print(i, happy_when_more_than)
# if s < R[i]:
# return 0
# return i
# if s < P[i]:
# not_happy += 1
# s = s*(1-F[i]/100) - A[i]
happy_when_more_than.sort()
# print(happy_when_more_than)
# print(min_speed)
out = ceil(max(happy_when_more_than[(n+1)//2 - 1], min_speed))
print(out)
# sys.stdout.write("\n".join(map(str, out)) + "\n") # one value per line
# print(*out) # space separated on one line
# print(f"{ans:.6f}") # float with 6 decimals
# print("\n".join("".join(row) for row in g)) # grid of chars
main()
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 3
1000 5 5 0 20 20 20 50 50 50 0 99 |
| correct output |
|---|
| 145 |
| user output |
|---|
| 145 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 10
1000000 1000000 1000000 99 1000000 1000000 1000000 99 1000000 1000000 1000000 99 1000000 1000000 1000000 99 ... |
| correct output |
|---|
| 2010101010101010100000000 |
| user output |
|---|
| 2010101010101010100000000 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 7
794772 933488 441001 5 271493 536110 509532 51 962838 821872 870163 38 499748 375441 611720 27 ... |
| correct output |
|---|
| 19316405 |
| user output |
|---|
| 19316405 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 3
596853 888598 841235 97 66172 267459 123646 63 797926 471325 495185 83 |
| correct output |
|---|
| 81642158 |
| user output |
|---|
| 81642158 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 1
96033 88994 378596 21 |
| correct output |
|---|
| 96033 |
| user output |
|---|
| 96033 |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 4
621429 570665 136758 47 960437 633256 497081 80 609067 68711 635017 1 952965 878149 492025 33 |
| correct output |
|---|
| 19366822 |
| user output |
|---|
| 19366822 |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 4
318031 108177 756250 50 502140 162500 94476 8 20779 421098 576089 37 839335 802331 61705 28 |
| correct output |
|---|
| 6474336 |
| user output |
|---|
| 6474336 |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 10
267853 777820 375951 88 988230 882388 775839 83 967127 555787 30414 59 813651 989181 261150 83 ... |
| correct output |
|---|
| 114240784216 |
| user output |
|---|
| 114240784216 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 10
861881 84483 508595 97 274330 38611 473 18 695015 614973 493097 97 770531 391287 334900 98 ... |
| correct output |
|---|
| 26667465547194 |
| user output |
|---|
| 26667465547194 |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 6
993908 158176 414002 83 50631 75954 861168 68 98702 383452 611097 7 953893 532084 225127 4 ... |
| correct output |
|---|
| 46921821 |
| user output |
|---|
| 46921821 |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 4
388404 393603 132467 24 739054 45905 89323 17 259460 850672 530957 26 420175 673047 31765 58 |
| correct output |
|---|
| 2895218 |
| user output |
|---|
| 2895218 |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 8
643002 391445 280110 17 195187 908655 709512 0 354760 527205 486247 77 84740 350249 581194 78 ... |
| correct output |
|---|
| 250399569 |
| user output |
|---|
| 250399569 |
