DMOPC '17 Contest 2 P6 - Lazy Days

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 0.6s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Bob is kicking back and relaxing today! He plans to continually watch TV for N hours. His TV has two channels each of which has a new show every hour. Every show has a rating from 0 to 10^6. Arrays A and B will represent the ratings of the shows of the first and second channel respectively. Bob wants to watch the shows so that he maximizes the minimum of the ratings of the shows he watches. Additionally, he is lazy, so he doesn't like reaching for his remote. Help Bob find out the most he can get out of his relaxation if he switches channels at most K times for K=0, 1, 2, \ldots ,N. Bob begins on the first channel, and can switch the channel right before any show.

Constraints

For all subtasks, 0\le A_i, B_i\le 10^6 for 1\le i\le N.

Subtask 1 [20%]

1\le N \le 2\,000

Subtask 2 [80%]

1\le N \le 200\,000

Input Specification

The first line will contain one integer representing N.

The second line will contain N space-separated integers representing array A.

The third line will contain N space-separated integers representing array B.

Output Specification

Output N+1 lines. On the i^{\text{th}} line, output the maximum possible minimum Bob can achieve if he switches channels at most i-1 times.

Maximizing the minimum - consider the minimum of ratings of the TV shows Bob watches. This minimum changes depending on at what times Bob switches the channel. To maximize the minimum is to find the largest such value over all possible ways Bob can switch channels in i-1 switches or less.

Sample Input 1

6
10 21 15 13 17 15
18 20 18 22 14 19

Sample Output 1

10
14
15
17
17
17
17

Explanation for Sample 1

For zero switches, Bob can only sit back and watch the entire first channel. With one switch, Bob can change the channel right before the first show and watch the entire second channel. For two switches, Bob changes the channel before the first and fifth shows. For three switches, Bob also changes the channel before the sixth show. Even with more switches, Bob cannot get any better value than 17.

Sample Input 2

5
1 2 1 2 1
2 1 2 1 2

Sample Output 2

1
1
1
1
1
2

Comments


  • 0
    r3mark  commented on Nov. 14, 2017, 9:15 p.m.

    Maximizing the minimum - consider the minimum of ratings of the TV shows Bob watches. This minimum changes depending on at what times Bob switches the channel. To maximize the minimum is to find the largest such value over all possible ways Bob can switch channels in K switches or less.