[codeforces1061D]TV Shows

time limit per test : 2 seconds
memory limit per test : 256 megabytes

There are n n n TV shows you want to watch. Suppose the whole time is split into equal parts called “minutes”. The i-th of the shows is going from l i − t h l_i-th lith to r i − t h r_i-th rith minute, both ends inclusive.

You need a TV to watch a TV show and you can’t watch two TV shows which air at the same time on the same TV, so it is possible you will need multiple TVs in some minutes. For example, if segments [ l i , r i ] [l_i,r_i] [li,ri] and [ l j , r j ] [l_j,r_j] [lj,rj] intersect, then shows i i i and j j j can’t be watched simultaneously on one TV.

Once you start watching a show on some TV it is not possible to “move” it to another TV (since it would be too distracting), or to watch another show on the same TV until this show ends.

There is a TV Rental shop near you. It rents a TV for x x x rupees, and charges y ( y < x ) y (y<x) y(y<x) rupees for every extra minute you keep the TV. So in order to rent a TV for minutes [ a ; b ] [a;b] [a;b] you will need to pay x + y ⋅ ( b − a ) x+y⋅(b−a) x+y(ba).

You can assume, that taking and returning of the TV doesn’t take any time and doesn’t distract from watching other TV shows. Find the minimum possible cost to view all shows. Since this value could be too large, print it modulo 1 0 9 + 7 10^9+7 109+7.

Input

The first line contains integers n n n , x x x and y y y ( 1 ≤ n ≤ 1 0 5 , 1 ≤ y < x ≤ 1 0 9 ) (1≤n≤10^5, 1≤y<x≤10^9) (1n105,1y<x109) — the number of TV shows, the cost to rent a TV for the first minute and the cost to rent a TV for every subsequent minute.
Each of the next n n n lines contains two integers l i l_i li and r i ( 1 ≤ l i ≤ r i ≤ 1 0 9 ) ri (1≤l_i≤r_i≤10^9) ri(1liri109) denoting the start and the end minute of the i − t h i-th ith TV show.

Output

Print exactly one integer — the minimum cost to view all the shows taken modulo 1 0 9 + 7 10^9+7 109+7.

Examples

Input

5 4 3
1 2
4 10
2 4
10 11
5 9

Output

60

Input

6 3 2
8 20
6 22
4 15
20 28
17 25
20 27

Output

142

Input

2 1000000000 2
1 2
2 3

Output

999999997

Note

In the first example, the optimal strategy would be to rent 3 3 3 TVs to watch:
Show [ 1 , 2 ] [1,2] [1,2] on the first TV,
Show [ 4 , 10 ] [4,10] [4,10] on the second TV,
Shows [ 2 , 4 ] , [ 5 , 9 ] , [ 10 , 11 ] [2,4],[5,9],[10,11] [2,4],[5,9],[10,11] on the third TV.

This way the cost for the first TV is 4 + 3 ⋅ ( 2 − 1 ) = 7 4+3⋅(2−1)=7 4+3(21)=7, for the second is 4 + 3 ⋅ ( 10 − 4 ) = 22 4+3⋅(10−4)=22 4+3(104)=22 and for the third is 4 + 3 ⋅ ( 11 − 2 ) = 31 4+3⋅(11−2)=31 4+3(112)=31, which gives 60 60 60 int total.
In the second example, it is optimal watch each show on a new TV.
In third example, it is optimal to watch both shows on a new TV. Note that the answer is to be printed modulo 1 0 9 + 7 10^9+7 109+7.

题意:
n n n个电视节目,第 i i i个电视节目的观看区间是 [ l i , r i ] [l_i,r_i] [li,ri],你可以同时看多台电视,但是观看区间有交集的两个电视节目不能在同一台电视上观看,在时段 [ a , b ] [a,b] [a,b]租用一台电视的费用是 x + y ∗ ( b − a ) x+y*(b-a) x+y(ba)请问要看完所有电视节目至少需要多少钱。

题解:
multiset的性质。
先把电视节目按照 l i l_i li为第一关键字, r i r_i ri为第二关键字升序排序。对于一个电视节目 i i i来说,看这个电视节目所需要的最少的费用就是 m i n ( x + ( r i − l i ) ∗ y , ( r i − n o w ) ∗ y ) min(x+(r_i-l_i)*y,(ri-now)*y) min(x+(rili)y,(rinow)y) n o w now now为当前multiset里面第一个小于 l i l_i li的元素。然后最后把 r i r_i ri放入multiset即可

#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int n;
ll x,y;
struct Ds{
    int l,r;
}a[100004];
inline bool dex(Ds A,Ds B){return A.l==B.l?A.r<B.r:A.l<B.l;}
multiset<int>tr;
multiset<int>::iterator it;
int w33ha(){
    tr.clear();
    tr.insert(MOD);
    tr.insert(-MOD);
    for(int i=1;i<=n;i++)scanf("%d%d",&a[i].l,&a[i].r);
    sort(a+1,a+n+1,dex);
    ll ans=0;
    for(int i=1;i<=n;i++){
        it=(--tr.lower_bound(a[i].l));
        int now=(*it);
        if(it==tr.begin()||1LL*(a[i].r-now)*y>1LL*x+1LL*(a[i].r-a[i].l)*y){
            ans=(int)((0LL+ans+(1LL*x+1LL*(a[i].r-a[i].l)*y))%MOD);
        }
        else{
            ans=(int)((0LL+ans+(1LL*(a[i].r-now)*y))%MOD);
            tr.erase(it);
        }
        tr.insert(a[i].r);
    }
    printf("%d\n",ans);
    return 0;
}
int main(){
    while(scanf("%d%lld%lld",&n,&x,&y)!=EOF)w33ha();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值