[codeforces1061D]TV Shows

版权声明:辛辛苦苦码字,你们转载的时候记得告诉我 https://blog.csdn.net/dxyinme/article/details/84455607

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

There are 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 to r i t h r_i-th 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] and [ l j , r j ] [l_j,r_j] intersect, then shows i i and 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 rupees, and charges 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] you will need to pay x + y ( b a ) x+y⋅(b−a) .

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 .

Input

The first line contains integers n n , x x and y y ( 1 n 1 0 5 , 1 y < x 1 0 9 ) (1≤n≤10^5, 1≤y<x≤10^9) — 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 lines contains two integers l i l_i and r i ( 1 l i r i 1 0 9 ) ri (1≤l_i≤r_i≤10^9) denoting the start and the end minute of the i t h i-th TV show.

Output

Print exactly one integer — the minimum cost to view all the shows taken modulo 1 0 9 + 7 10^9+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 TVs to watch:
Show [ 1 , 2 ] [1,2] on the first TV,
Show [ 4 , 10 ] [4,10] on the second TV,
Shows [ 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 , for the second is 4 + 3 ( 10 4 ) = 22 4+3⋅(10−4)=22 and for the third is 4 + 3 ( 11 2 ) = 31 4+3⋅(11−2)=31 , which gives 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 .

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

题解:
multiset的性质。
先把电视节目按照 l i l_i 为第一关键字, r i r_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) n o w now 为当前multiset里面第一个小于 l i l_i 的元素。然后最后把 r i r_i 放入multiset即可

#include<bits/stdc++.h>
#define LiangJiaJun main
#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 LiangJiaJun(){
    while(scanf("%d%lld%lld",&n,&x,&y)!=EOF)w33ha();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/dxyinme/article/details/84455607