题目链接

https://vjudge.net/problem/CodeForces-1061D

题面

Description

There are nn 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 li-th to ri-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 [li,ri] and [lj,rj] intersect, then shows i and 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 xx rupees, and charges y (y<x) rupees for every extra minute you keep the TV. So in order to rent a TV for minutes [a;b] you will need to pay 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 \(10^9+7\).

Input

The first line contains integers n, x and y (\(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 lines contains two integers li and ri (\(1≤li≤ri≤10^9\)) denoting the start and the end minute of the i-th TV show.

Output

Print exactly one integer — the minimum cost to view all the shows taken modulo 109+7109+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 33 TVs to watch:

  • Show [1,2] on the first TV,
  • Show [4,10] on the second TV,
  • Shows [2,4],[5,9],[10,11] on the third TV.

This way the cost for the first TV is 4+3⋅(2−1)=7, for the second is 4+3⋅(10−4)=22 and for the third is 4+3⋅(11−2)=31, which gives 6060 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 \(10^9+7\)

题意

给定 n 个电视节目和两个参数 x,y。你想要看全部的电视节目,但是同一个电视机同一个时刻只能播放一个电视节目,所以你只能多租赁电视机。在时间 [l,r] 租赁一台电视机的花费是 x + y (r−l)。一台电视机不可以在节目没有播放完时中断播放,播放时间包括r,也就是说如果一个节目在r时结束,另一个节目在r时开始时,这台电视机不能给刚开始的节目用。求最小花费。答案对 1e9+7 取模。

题解

首先我们把电视节目排序,排序按左端点小的在前,左端点相同时按右端点小的在前,因为靠前的节目肯定要先看,然后我们用一个multiset维护当前已经有的电视机的使用结束时间,首先对于第一个节目,此时还没有电视机,肯定要先买一台电视机,加上相应的花费,然后这台电视机在\(r_1\)时使用结束,set中有一台电视机的信息

然后从2到n开始循环,每次循环找到一台电视机的使用结束时间比这个节目的开始时间早,离这个节目开始最近的电视,没有的话就要再租一台电视机,如果有的话,就要判断一下,看是使用已有的电视机比较便宜还是再租一台比较便宜,如果使用已有电视机比较便宜的话,那么就要把这台电视机的结束时间更新到这次节目的结束时间,如果再租一台比较便宜,就要新加入一台使用结束时间在这次节目结束时间的电视机,同时计算花费,这样一直贪心选取计算答案即可。

为什么要这么贪心呢,因为如果在一个节目开始时间之前有多台电视机可以继续使用的话,结束时间更早的电视机肯定不如结束时间较晚的电视机优,因为它要花费更多的单位时间的租金。

至于找到结束时间最近的电视机,就直接使用\(lower\_bound\)即可,找到第一个大于等于的,再-1就是比它小的。

代码有点丑

AC代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#define N 100050
using namespace std;
typedef long long ll;
const int p = (int)1e9 + 7;
struct node {
ll l, r;
bool operator < (const node &b) const {
if (l == b.l) return r < b.r;
else return l < b.l;
}
} a[N];
int main() {
multiset<ll> s;
ll n, x, y;
scanf("%lld%lld%lld", &n, &x, &y);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &a[i].l, &a[i].r);
}
sort (a + 1, a + n + 1);
s.insert(a[1].r);
multiset<ll>::iterator it;
ll ans = (x + y * (a[1].r - a[1].l) % p) % p;
for (int i = 2; i <= n; i++) {
it = s.lower_bound(a[i].l);
if (it == s.begin()) {
ans = (ans + x + y * (a[i].r - a[i].l) % p) % p;
s.insert(a[i].r);
}
else {
it--;
while (a[i].l == *it && it != s.begin()) {
it--;
}
if (*it == a[i].l) {
ans = (ans + x + y * (a[i].r - a[i].l) % p) % p;
}
else {
if ((a[i].l - *it) * y < x) {
ans = (ans + (a[i].r - *it) * y % p) % p;
s.erase(it);
}
else {
ans = (ans + x + (a[i].r - a[i].l) * y % p) % p;
}
}
s.insert(a[i].r);
}
}
cout << ans % p << endl;
return 0;
}

CodeForces-1061D TV Shows的更多相关文章

  1. Codeforces Round #523 (Div. 2) D. TV Shows

    传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 题意: 有n个节目,每个节目都有个开始时间和结束时间. 定义x,y分别为租电视需要的花 ...

  2. Codeforces Round #523 (Div. 2) D. TV Shows 模拟(多重集 先把所有区间加入多重集合)+贪心+二分

    题意:给出n个电视节目的起始和结束时间  并且租一台电视需要x +y*(b-a)  [a,b]为时段 问完整看完电视节目的最小花费是多少 思路:贪心的思想 情况1 如果新租一台电视的花费<=在空 ...

  3. 【codeforces】【Round#523D】TV shows

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

  4. 【贪心】【CF1061D】 TV Shows

    Description 给定 \(n\) 个电视节目和两个参数 \(x,y\).你想要看全部的电视节目,但是同一个电视机同一个时刻只能播放一个电视节目,所以你只能多租赁电视机.在时间 \([l,r]\ ...

  5. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)

    链接: https://codeforces.com/contest/1247/problem/B2 题意: The only difference between easy and hard ver ...

  6. CodeForces - 1097F:Alex and a TV Show (bitset & 莫比乌斯容斥)

    Alex decided to try his luck in TV shows. He once went to the quiz named "What's That Word?!&qu ...

  7. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B. TV Subscriptions 尺取法

    B2. TV Subscriptions (Hard Version) The only difference between easy and hard versions is constraint ...

  8. Codeforces Round #523 (Div. 2)

    Codeforces Round #523 (Div. 2) 题目一览表 来源 考察知识点 完成时间 A Coins cf 贪心(签到题) 2018.11.23 B Views Matter cf 思 ...

  9. 10 Best TV Series Based On Hacking And Technology

    Technology is rapidly becoming the key point in human lives. Here we have discussed top TV shows whi ...

随机推荐

  1. PHP精度问题

    PHP 为任意精度数学计算提供了二进制计算器(Binary Calculator),它支持任意大小和精度的数字,以字符串形式描述 bcadd — 加法bccomp — 比较bcdiv — 相除bcmo ...

  2. Pj Immediate Decodability

    判断一个串是否是其他的前缀 我们需要建立一颗tire树 在插入边的时候,如果遇到一个其他串的结尾,那么就说明至少有一个串,是插入串的前缀.如果在插入完后没有新增的节点,那么插入的串就是其他串的前缀 # ...

  3. 【洛谷P1323】删数问题

    删数问题 题目链接 首先找出最小的k个数:用堆每次取出最小的元素p,将p*2+1和p*4+5压入堆. 贪心求最大数:从前往后找第一个data[j+1]>data[j],删除data[j].(链表 ...

  4. centos 6.5 配置nginx环境

    1.卸载系统中默认的php和httpd [root@x ~]# yum remove httpd* php* Loaded plugins: fastestmirror Setting up Remo ...

  5. (转)Unity 和 Cocos2d-x 越渐流行,国内公司开发「自研游戏引擎」的意义何在?

    分几个角度来说:一.我认为,Unity3D将无可挽回的,或者说,势在必得的,成为接下来很多年内,世界移动领域游戏引擎市场霸主.回顾历史,正如同咱们经历过一次又一次的互联网时代变革一样,x86,wind ...

  6. php获取设备的宽度和高度

    php获取设备的宽度和高度 如果前台没有传输当前请求的宽度和高度,我们有时候需要用php借助javascript获取屏幕的宽和高,以控制现实的样式. 代码如下: <?php /* * 获取设备宽 ...

  7. HAN模型理解2

    Hierarchical Attention Networks for Document Classification 论文的理解 在论文的摘要中,它提出了论文的两个特点.第一个就是对应文章所有具有的 ...

  8. pycharm中文乱码问题 总结

    前言: 这几天刚刚开始学习python,然后就安装了pycharm,但是那个中文乱码的问题真是让人心烦,在网上找了好久,都写得好乱,今天终于让我解决了,在这里总结一下经验,希望可以帮到你们 问题:如下 ...

  9. 准备篇(二)C语言

    因为C语言部分打算单独维护,所以 目录: 1. C语言基础篇(零)gcc编译和预处理 2. C语言基础篇(一)关键字 3. C语言基础篇(二)运算符 4. C语言指针篇(一)指针与指针变量 5. C语 ...

  10. Sqlite客户端的使用

    打开一个数据库sqlite3 ${databaseName} 查看当前打开的数据库.database 查看当前打开的数据库中的表.table 查看指定表结构(实际输出是建表语句).schema ${t ...