1445 - Pku3245 Sequence Partitioning

Input

Output

Examples

Input

4 6
4 3
3 5
2 5
2 4

Output

9

Hint

An available assignment is the first two pairs are assigned into the first part and the last two pairs are assigned into the second part. Then B1 > A3, B1 > A4, B2 > A3, B2 > A4, max{A1, A2}+max{A3, A4} ≤ 6, and minimum max{B1+B2, B3+B4}=9.

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题