PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000063. Chọn những bông hoa đẹp nhất (Q - Flowers)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chọn những bông hoa đẹp nhất (Q - Flowers)
Q - Flowers
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are flowers in a row. Flower has height and beauty . Heights are a permutation of . Remove some flowers, keeping the original order, so that remaining heights are strictly increasing and their total beauty is maximized.
Input
The first line contains ; the second contains ; the third contains .
Output
Print the maximum possible total beauty.
Subtasks
Original constraints: ; heights form a permutation of ; .
- Subtask 1 (20 points): ; is a permutation of ; .
- Subtask 2 (30 points): ; is a permutation of ; .
- Subtask 3 (50 points): ; is a permutation of ; .
Examples
Input
4
3 1 4 2
10 20 30 40
Output
60
Explanation
Keep flowers and , whose heights are and beauties are . Their total beauty is .