PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000064. Thuê ba bảng hiển thị (C - Three displays)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Thuê ba bảng hiển thị (C - Three displays)
C - Three displays
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are displays arranged in order. Display has font size and rental cost . Choose exactly three indices with and minimize . Print -1 if no such triple exists.
Input
The first line contains ; the second contains font sizes ; the third contains costs .
Output
Print the minimum total cost, or -1 if no valid triple exists.
Subtasks
Original constraints: ; ; .
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Explanation
Choose positions : font sizes are , and the cost is .