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. 【原】php中fastcgi和php-fpm是什么东西

    fastcgi 是一个与平台无关,与语言无关,任何语言只要按照它的接口来实现,就能实现自己语言的fastcgi能力和web server 通讯. PHP-CGI就是PHP实现的自带的FastCGI管理 ...

  2. 调用百度汇率api 获取各国的汇率值

    设置一个定时任务,每天更新汇率java代码如下 package com.thinkgem.jeesite.modules.huiLvApi.service; import java.io.Buffer ...

  3. 任意promise串行执行算法 - 童彪

      // 任意promise串行执行算法 - 童彪 function runAllPromise() { var p1 = new Promise((resove, reject) => { s ...

  4. 本周总结(19年暑假)—— Part7

    日期:2019.8.25 博客期:113 星期日

  5. java编程,通过代理服务器访问外网的FTP

    有些时候我们的网络不能直接连接到外网, 需要使用http或是https或是socket代理来连接到外网, 这里是java使用代理连接到外网的一些方法, 希望对你的程序有用.方法一:使用系统属性来完成代 ...

  6. 《精通Objective-C》书籍目录

    1.入门 2.使用类 3.对象和消息传递 4.内存管理 5.预处理器 6.专家级技巧:使用ARC 7.运行时系统 8.运行时系统的结构 9.专家级技巧:使用运行时系统API 10.Foundation ...

  7. 十六 Spring的JDBC模版入门,默认连接池

    Spring是EE开发一站式框架,有EE开发的每层的解决方案,Spring对持久层也提供了解决方案:ORM模块和JDBC的模版

  8. Qt中QListWidget的verticalScrollMode选项设置为ScrollPerPixel无效果的原因

    设置为ScrollPerPixel无效果,根据Qt手册的描述,需要在设置一次setSingleStep()的值,才会生效

  9. 标准模板库中的队列(queue)

    //C++数据结构与算法(第4版) Adam Drozdek 著  徐丹  吴伟敏<<清华大学出版社>> 队列容器默认由deque实现,用户也可以选择list容器来实现.如果用 ...

  10. 「Luogu P3820 小D的地下温泉」

    这道题的考点比较多. 前置芝士 BFS(DFS),这两种算法在这道题中并没有什么特别突出的地方,基本就是自己看心情写(本文以DFS为准,所以我心情是好是坏呢?) 连通块,可以将每一个温泉看作一个连通块 ...