Sequence Partitioning

TimeLimit:8000MS  MemoryLimit:65536K
64-bit integer IO format:%lld
未提交 | 登录后收藏
Problem Description

Given a sequence of N ordered pairs of positive integers (Ai, Bi), you have to partition it into several contiguous parts. Let p be the number of these parts, whose boundaries are (l1, r1), (l2, r2), ... ,(lp, rp), which satisfy li = ri − 1 + 1, li ri, l1 = 1, rp = n. The parts themselves also satisfy the following restrictions:

  1. For any two pairs (Ap, Bp), (Aq, Bq), where (Ap, Bp) is belongs to the Tpth part and (Aq, Bq) the Tqth part. If Tp < Tq, then Bp > Aq.

  2. Let Mi be the maximum A-component of elements in the ith part, say

    Mi = max{Ali, Ali+1, ..., Ari}, 1 ≤ ip

    it is provided that

    where Limit is a given integer.

Let Si be the sum of B-components of elements in the ith part. Now I want to minimize the value

max{Si:1 ≤ i ≤ p}

Could you tell me the minimum?

Input

The input contains exactly one test case. The first line of input contains two positive integers N (N ≤ 50000), Limit (Limit ≤ 231-1). Then follow N lines each contains a positive integers pair (A, B). It's always guaranteed that

max{ A 1, A 2, ..., An} ≤ Limit
Output
Output the minimum target value.
SampleInput
4 6
4 3
3 5
2 5
2 4
SampleOutput
9
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数2
总提交量3
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: