AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

BAPC25-044.Excruciating Elevators

Medium · 2 s · 256 MB

  • icpc
  • bapc
  • 2025

It is the 25th of May, 3025. The EEMCS building at TU Delft has grown to 10610^6106 floors beyond the ground floor! The floors are now numbered 0,1,…,1060,1,\ldots,10^60,1,…,106, but there are still only four elevators. Moreover, the elevators have malfunctioned and are currently turned off. As employee of the Building Ascension Plans Company, you are tasked to fix the elevators.

You first have to order some components, which will take a month to arrive at the ground floor. After collecting the components, you must visit nnn floors f1,…,fnf_1,\ldots,f_nf1​,…,fn​ in order. At each floor fif_ifi​, you must replace some component, which takes tit_iti​ seconds. After replacing the final component, the elevators will be fixed.

The stairs have long been removed, since people got tired of walking up millions of flights of stairs. You thus have to use the elevators to travel between the floors. You can turn on the elevators, but when you turn one on, you can no longer turn it off. Once turned on, an elevator will move up and down between floors 000 and 10610^6106 indefinitely. The elevators move at a speed of one floor every second without stopping, but you are agile enough to enter and exit.

You know exactly when the components will arrive. In the meantime, you can determine when to turn on each elevator. This timing determines the starting configuration of each elevator when the components arrive. Since you have a month, you can enforce any arbitrary starting configuration of the elevators. What is the minimum possible time to fix the elevators?

As an example, consider the first sample input. You can ensure one elevator starts at ground floor going up, and another starts at floor 750 000750\,000750000 going up. Entering the former elevator immediately, you arrive at floor 600 000600\,000600000 after 600 000600\,000600000 seconds. After 50 00050\,00050000 more seconds, you finish replacing the component at floor 600 000600\,000600000. In the meantime, the latter elevator reached the top floor after 250 000250\,000250000 seconds, when it started going down. Now, 400 000400\,000400000 seconds later, this elevator is at floor 600 000600\,000600000 going down. You can enter this elevator immediately and exit 200 000200\,000200000 seconds later at floor 400 000400\,000400000. Finally, after 150 000150\,000150000 seconds, you finish replacing the component at floor 400 000400\,000400000, and the elevators are fixed! The total time is 600 000+50 000+200 000+150 000=1 000 000600\,000+50\,000+200\,000+150\,000=1\,000\,000600000+50000+200000+150000=1000000 seconds.

Giriş formatı

The input consists of:

• One line with an integer nnn (1≤n≤351\leq n\leq 351≤n≤35), the number of floors to visit.

• One line with nnn integers f1,…,fnf_1,\ldots,f_nf1​,…,fn​ (0≤fi≤1060\leq f_i\leq10^60≤fi​≤106 for each iii), the numbers of the floors you must visit.

• One line with nnn integers t1,…,tnt_1,\ldots,t_nt1​,…,tn​ (1≤ti≤1091\leq t_i\leq10^91≤ti​≤109 for each iii), the necessary time spent on each floor in seconds.

No two consecutive floors fi,fi+1f_i,f_{i+1}fi​,fi+1​ are equal, and f1f_1f1​ is non-zero.

Çıxış formatı

Output the minimum possible time in seconds to fix the elevators after the components have arrived and you start at the ground floor.

Qeyd

Source: Benelux Algorithm Programming Contest 2025 · Author: Albert Eikelenboom · License: CC BY-SA 4.0 · Original: https://bapc.eu · Statement adapted for AlgoLens and shared under the same license.

Nümunələr

Giriş #1

2
600000 400000
50000 150000

Çıxış #1

1000000

Giriş #2

10
1 2 3 4 5 6 7 8 9 10
1 1 1 1 1 1 1 1 1 1

Çıxış #2

4000012