codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

987C.md (1929B)


      1 Source: https://codeforces.com/problemset/problem/987/C
      2 
      3 C. Three displays
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
     22 
     23 There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i \lt j \lt k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i \lt s_j \lt s_k$ should be held.
     24 
     25 The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay.
     26 
     27 Input
     28 
     29 The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays.
     30 
     31 The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road.
     32 
     33 The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le 10^8$) — the rent costs for each display.
     34 
     35 Output
     36 
     37 If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i \lt j \lt k$ such that $s_i \lt s_j \lt s_k$.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 5  
     45 2 4 5 4 10  
     46 40 30 20 10 40
     47 ```
     48 
     49 Output
     50 
     51 ```
     52 90
     53 ```
     54 
     55 Input
     56 
     57 ```
     58 3  
     59 100 101 100  
     60 2 4 5
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 -1
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 10  
     73 1 2 3 4 5 6 7 8 9 10  
     74 10 13 11 14 15 12 13 13 18 13
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 33
     81 ```
     82 
     83 Note
     84 
     85 In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 \lt s_4 \lt s_5$ ($2 \lt 4 \lt 10$), and the rent cost is $40 + 10 + 40 = 90$.
     86 
     87 In the second example you can't select a valid triple of indices, so the answer is -1.