【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  

原文地址:https://www.cnblogs.com/Paul-Guderian/p/10014571.html

时间: 2024-10-16 17:21:15

【codeforces】【Round#523D】TV shows的相关文章

【codeforces VK Cup Round 1】BDE题解

B. Group Photo 2 (online mirror version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Many years have passed, and n friends met at a party again. Technologies have leaped forward since the

【codeforces ZeptoLab Code Rush 2015】ABCD题解

A. King of Thieves time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output In this problem you will meet the simplified model of game King of Thieves. In a new ZeptoLab game called "King of Thieves&quo

【codeforces div3 19/10/23】A.Yet Another Dividing into Teams

1 #include<iostream> 2 #include<string> 3 #include<queue> 4 #include<stack> 5 #include<vector> 6 #include<map> 7 #include<cstdio> 8 #include<cstdlib> 9 #include<algorithm> 10 #include<set> 11 #in

【codeforces 19/10/24 div2】C. Minimize The Integer

1 #include<iostream> 2 #include<string> 3 #include<queue> 4 #include<stack> 5 #include<vector> 6 #include<map> 7 #include<cstdio> 8 #include<cstdlib> 9 #include<algorithm> 10 #include<set> 11 #in

【codeforces 19/10/26 div2】E.Rock In Push

1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 using namespace std; 5 6 #define mfor(i,a,b) for(register int i=(a);i<=(b);i++) 7 #define mrep(i,a,b) for(register int i=(a);i>=(b);i--) 8 typedef long long int LL; 9

【codeforces 19/11/06 div2】A. Maximum Square

1 #include<iostream> 2 #include<algorithm> 3 #include<map> 4 using namespace std; 5 6 map<int, int>cnt; 7 8 int main() 9 { 10 int T; 11 cin >> T; 12 while (T--) 13 { 14 cnt.clear(); 15 int n; 16 cin >> n; 17 for (int i

【codeforces 19/11/06 div2】C. Tile Painting

1 #include <iostream> 2 using namespace std; 3 4 typedef long long LL; 5 6 LL gcd(LL a, LL b) 7 { 8 if (!b) return a; 9 return gcd(b, a % b); 10 } 11 12 int min(int a, int b) 13 { 14 return a < b ? a : b; 15 } 16 17 int main() 18 { 19 LL x; 20 ci

【codeforces 19/11/06 div2】D. 0-1 MST

1 #include<iostream> 2 #include<set> 3 #include<map> 4 #include<queue> 5 #include<algorithm> 6 using namespace std; 7 8 const int maxn = 100010; 9 int n, m; 10 set<int>e[maxn]; 11 set<int>node; 12 int fa[maxn]; 13

【排序】【规律】Codeforces Round #254 (Div. 2) - D. Rooter&#39;s Song

D. DZY Loves FFT Source http://codeforces.com/contest/445/problem/D Description Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w?×?h, represented by a re