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. keil中的一些技巧

    一  在Keil5中使用代码格式化工具Astyle(插件)https://blog.csdn.net/u010160335/article/details/78587411 二 将keil中的内存变量 ...

  2. 监听EditView中的文本改变事件详解--转

    转自: http://blog.csdn.net/zoeice/article/details/7700529 android中的编辑框EditText也比较常用,那比如在搜索框中,没输入一个字,下面 ...

  3. windows网络编程-C语言实现简单的UDP协议聊天

    与TCP协议下编写服务端程序代码类似,但因为是无连接的形式,所以不需要监听. 这次,我用了一点不同的想法:我建立一个服务端,用了两个端口和两个套接字,把服务端作为一个数据转发的中转站,使得客户机之间进 ...

  4. Lightroom中几个重要名词术语的解释

    Lightroom是照片管理.处理.发布的综合性智能软件,里面有几个重要的专有技术名词,通过我的理解做一个总结: 一.目录(Catalog) 就是Lightroom的数据库,会把用户的照片的信息.照片 ...

  5. Python 基础之生成器

    一.生成器表达式 生成器本质是迭代器,允许自定义逻辑的迭代器迭代器和生成器区别:迭代器本身是系统内置的,重写不了.而生成器是用户自定义的,可以重写迭代逻辑生成器可以用来钟方式创建:    (1)生成器 ...

  6. 解决vue更新默认值时出现的闪屏问题

    在Vue项目中,对于一个展示用户个人信息的页面.有以下需求,需要判断用户个人信息是否填充过,如果填充过,需要在页面中展示已填充项(未填充项不展示):如果未填充过,需要在页面中显示另外一种元素(提示用“ ...

  7. 【剑指Offer面试编程题】题目1387:斐波那契数列--九度OJ

    题目描述: 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.斐波那契数列的定义如下: 输入: 输入可能包含多个测试样例,对于每个测试案例, 输入包括一个整数n(1< ...

  8. Windows驱动开发-IoCompleteRequest

    IoCompleteRequest 例程表示调用者的已经完成了对指定I/O请求的所有处理操作,并且向I/O管理器返回指定的IRP报文. //函数原型 VOID IoCompleteRequest( I ...

  9. 图解jvm--(一)jvm内存结构

    jvm内存结构 1.程序计数器 1.1 定义 Program Counter Register 程序计数器(寄存器) 作用,记住下一条jvm指令的执行地址 特点 是线程私有的 (唯一)不会存在内存溢出 ...

  10. Python 2 与 3 共存了 11 年,新年就要和它道别

    在 Python 3.9 都已经进入 dev 版本的 2020 年,Python 2 终于要和我们告别了. 2 and 3 Python 2 第一个版本发布于 2000 年 10 月 16 日,到今年 ...