#FT0000083. Chọn hoa đẹp nhất (Flowers)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chọn hoa đẹp nhất (Flowers)
Flowers
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are flowers arranged from left to right. Flower has height and beauty . All heights are distinct.
You may remove any flowers without changing the relative order of those remaining. Their heights, read from left to right, must form a strictly increasing sequence.
The value of a choice is the sum of the beauties of the remaining flowers. Find the maximum achievable sum.
Input
The first line contains .
The second line contains exactly heights .
The third line contains exactly beauties , with belonging to the flower of height .
Output
Print the maximum total beauty of a valid set of remaining flowers.
Subtasks
- Subtask 1 (20 points): ; ; ; all are pairwise distinct.
- Subtask 2 (30 points): ; ; ; all are pairwise distinct.
- Subtask 3 (50 points): ; ; ; all are pairwise distinct.
Examples
Input
4
3 1 4 2
10 20 30 40
Output
60
Explanation
The four (height, beauty) pairs are , , , .
Keeping flowers and produces heights and beauty . Keeping flowers and is also valid, but gives only . Flowers cannot all remain because heights do not increase. The maximum is 60.