time limit per test

2.0 s

memory limit per test

256 MB

input

standard input

output

standard output

Another semester has ended and Arthur finally achieved his dream of attending Data Structures I with all professors in the Mathematics Department. Now, he can finally pass this subject, but, like everyone expected, he didn't do any PAs (programming assignments), and all deadlines have passed.

Fortunately, all PAs can still be submitted for grading, but with a penalty given by: (late submission time) - (expected deadline time) for each PA.

Arthur, having taken Data Structures I so many times, knows exactly how much time he needs to complete each assignment. Now, he wants to write a program that determines the minimum sum of penalties that can be achieved, given he can do the PAs in any order.

It's worth noting that Arthur can't do more than one assignment at a time, since that skill is only learned in Data Structures II. Therefore, if Arthur starts working on an assignment, he needs to finish it before starting any other.

There is only one problem left: Arthur believes this problem to be unsettlingly similar to a PA, and, therefore, refuses to do it.

Help Arthur complete this task and, finally, take Data Structures II.

Input

The first line of input contains two integers 1 ≤ n ≤ 105 and 1 ≤ s ≤ 109, the amount of PAs Arthur needs to do and the time when he started to do them, respectively.

n lines follow, the i-th line contains two integers 1 ≤ ti ≤ 109 and 0 ≤ ei ≤ 109, the time Arthur takes to complete the i-th assignment and the expected deadline time for that assignment.

It is guaranteed s > ei for all i.

Output

Print the sum of all penalties if Arthur completes the PAs in the optimal order.

Example
Input

Copy
2 1
2 0
1 0
Output

Copy
6
Note

In the first example, if Arthur does the second PA first, he finishes it at time 2, and finishes the first one at time 4, making his total penalty equals to (2-0)+(4-0) = 6.

题意:第一行输入两个数,代表 n 个任务和开始做任务的时间 s ,接下来的n 行每行输入完成任务需要的时间 t 和该任务的截至时间 d ,每个任务都有一个罚时(罚时=完成任务的时间-该任务的截止时间),

求完成所有任务的最小总罚时。

题解:贪心处理,将完成任务的时间从小到大排序,若完成时间相同,按截至时间从小到大排序

#include<iostream>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
struct node
{
ll t;
ll d;
}p[];
bool cmp(node a,node b)
{
if(a.t!=b.t)
return a.t<b.t;
else
return a.d<b.d;
}
int main()
{
ll n,s;
cin>>n>>s;
for(int i=;i<n;i++)
{
cin>>p[i].t>>p[i].d;
}
sort(p,p+n,cmp);
ll cnt=;
for(int i=;i<n;i++)
{
//cout<<p[i].t<<' '<<p[i].d<<endl;
s=s+p[i].t;
cnt=cnt+s-p[i].d;
}
cout<<cnt<<endl;
return ;
}

E. MaratonIME does (not do) PAs的更多相关文章

  1. Delphi项目构成之单元文件PAS

    单元文件是Pascal源文件,扩展名为.pas. 有三种类型的单元文件: 窗体/数据模块和框架的单元文件(form/data module and frame units),一般由Delphi自动生成 ...

  2. Delphi 包的设计思想及它与PAS、BPL、DCU、DLL、OXC的关系。

    DCP ,BPL分别是什么文件,起什么作用?你在DELPHI中建立一个package然后保存一下,看看. bpl和Dll比较相似.只是BPL是BORLAND自己弄出来的东西!!!调用也和调用DLL相似 ...

  3. 5、利用控件TVCLZip和TIdFTP压缩文件并上传到FTP的线程单元pas 改进版

    用到临界区 保护写日志的函数: 递归函数 删除目录下的所有文件: 循环创建或判断FTP的目录: 可改进的地方:循环压缩深层次目录的所以文件: 实现断点续传,或断点下载: {************** ...

  4. F2063 Could not compile used unit 'tt.pas'

    install packge error F2063 Could not compile used unit 'tt.pas' 有可能是工程的pas文件相对路径不对.在工程管理看是否能打开文件,如果打 ...

  5. Android问题-XE5提示"[DCC Fatal Error] Project1.dpr(1): F1027 Unit not found: 'System.pas' or binary equivalents (.dcu/.o)"

    问题现象:Checking project dependencies...Compiling Project1.dproj (Debug, Android)dcc command line for & ...

  6. Messages.pas里的消息

    一.Windows 消息大全 这张表拷贝自万一兄的帖子:http://www.cnblogs.com/del/archive/2008/02/25/1079970.html 但是我希望自己能把这些消息 ...

  7. 问题-RZ安装后报错“RzBorder.pas”

    错误象现:[Error] RzBorder.pas(1429): Number of elements differs from declaration [Fatal Error] RzEdit.pa ...

  8. 问题-[致命错误] Project1.dpr(1): Unit not found: 'System.pas' or binary equivalents (DCU,DPU)

    问题现象:[致命错误] Project1.dpr(1): Unit not found: 'System.pas' or binary equivalents (DCU,DPU) 问题原因:由于删除D ...

  9. 问题-[Delphi]MainFrame.pas(4340): E2036 Variable required

    问题现象:写了一个TObjectList的Sort方法,但是写成ObjectList.Sort(@SortBridgeEDOReportQtys); 再F9时提示“E2036 Variable req ...

随机推荐

  1. Ubuntu18.04下Qt5.9.8连接mysql数据库失败的解决办法

    问题: 连接mysql数据库时,出现如下 提示: QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQ ...

  2. 一键设置Fluent环境变量小程序

    使用视频教程优酷播放地址: https://v.youku.com/v_show/id_XNDU2MTkwNDg5Mg==.html?spm=a2hzp.8244740.0.0 一键设置环境变量小软件 ...

  3. springmvc常用注解详解

    1.@Controller 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ...

  4. 刷题19. Remove Nth Node From End of List

    一.题目说明 这个题目是19. Remove Nth Node From End of List,不言自明.删除链表倒数第n个元素.难度是Medium! 二.我的解答 链表很熟悉了,直接写代码. 性能 ...

  5. 「SDOI2009」HH的项链

    「SDOI2009」HH的项链 传送门 数据加强了,莫队跑不过了. 考虑用树状数组. 先把询问按右端点递增排序. 然后对于每一种贝壳,我们都用它最右一次出现的位置计算答案. 具体细节看代码吧. 参考代 ...

  6. Genymotion设置代理至BurpSuite和Charles

    环境 Genymotion VirtualBox BurpSuite Charles 准备 怎么下载安装就不用说了,因为genymotion要依赖VirtualBox,所以要先把VirtualBox装 ...

  7. vb.net 写日志文件

    Module mod_LogAccessHt #Region "Const" Public Const __PREFIX_ERROR__ As String = "Err ...

  8. 图层CALayer的使用

    1.图层的意义 当UIView需要显示到屏幕上时,会调用drawRect:方法进行绘图,并且会将所有内容绘制在自己的图层上,绘制完毕后,系统会将图层拷贝到屏幕上,于是就完成了UIView的显示.   ...

  9. 2018 蓝桥杯省赛 B 组模拟赛

    C. 结果填空:U型数字 最近蒜头君喜欢上了U型数字,所谓U型数字,就是这个数字的每一位先严格单调递减,后严格单调递增.比如 212 就是一个U型数字,但是 333, 98, 567, 3131,就是 ...

  10. python deepcopy的替代方案

    from copy import deepcopy import marshal import timeit from multidict import CIMultiDict def test_de ...