time limit per test : 2 seconds
memory limit per test : 256 megabytes
There are 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 to 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 and intersect, then shows and 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 rupees, and charges rupees for every extra minute you keep the TV. So in order to rent a TV for minutes you will need to pay .
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 .
Input
The first line contains integers
,
and
— 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
lines contains two integers
and
denoting the start and the end minute of the
TV show.
Output
Print exactly one integer — the minimum cost to view all the shows taken modulo .
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
TVs to watch:
Show
on the first TV,
Show
on the second TV,
Shows
on the third TV.
This way the cost for the first TV is
, for the second is
and for the third is
, which gives
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
.
题意:
有
个电视节目,第
个电视节目的观看区间是
,你可以同时看多台电视,但是观看区间有交集的两个电视节目不能在同一台电视上观看,在时段
租用一台电视的费用是
请问要看完所有电视节目至少需要多少钱。
题解:
multiset的性质。
先把电视节目按照
为第一关键字,
为第二关键字升序排序。对于一个电视节目
来说,看这个电视节目所需要的最少的费用就是
为当前multiset里面第一个小于
的元素。然后最后把
放入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;
}