【codeforces】【Round#523D】TV shows

题意:n个节目,每个节目的播放时间为[li,ri],你需要选择一些电视机全部播放这些节目,一台电视机不能同时播放多个节目,选择一个新的电视机代价为x , 如果某台电视机的使用时间为[Li,Ri]需要付出(Ri-Li)*y的代价,问最小的代价;

题解:
        答案是选由于使用电视播放节目的代价是固定的,所以只需要让浪费的使用时间和选择一个新的电视的代价之和最小即可,左端点排序,对于[li,ri],每次选择前面使得rj<li的rj最大的(lj,rj),将x和(li-rj)*y比较讨论;

        cf的题解里面写了证明,但是我总感觉不太严谨的样子。。。。。

        具体实现用mulset;

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<set>
 4 #include<algorithm>
 5 using namespace std;
 6 const int N=100010 ,mod=1e9+7;
 7 int n,ans,x,y;
 8 struct node{
 9     int x,y;
10     bool operator <(const node&A)const{
11         return x == A.x ? y < A.y : x < A.x;
12     }
13 }a[N];
14 multiset<int>s;
15 multiset<int>::iterator it;
16 int main(){
17 //    freopen("D.in","r",stdin);
18 //    freopen("D.out","w",stdout);
19     scanf("%d%d%d",&n,&x,&y);
20     for(int i=1;i<=n;i++){
21         scanf("%d%d",&a[i].x,&a[i].y);
22         ans = (ans + 1ll * y * (a[i].y - a[i].x) %mod)%mod;
23     }
24     sort(a+1,a+n+1);
25     for(int i=1;i<=n;i++){
26         it = s.lower_bound(a[i].x);
27         if(it==s.begin() || 1ll*(a[i].x-*(--it)) * y >= x){
28             ans=(ans+x)%mod;
29             s.insert(a[i].y);
30         }else{
31             ans=(ans+1ll*(a[i].x-*it) * y%mod)%mod;
32             s.erase(it);
33             s.insert(a[i].y);
34         }
35     }
36     printf("%d\n",ans);
37     return 0;
38 } 
39  
View Code

 

猜你喜欢

转载自www.cnblogs.com/Paul-Guderian/p/10014571.html