E. MaratonIME does (not do) PAs
2.0 s
256 MB
standard input
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.
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.
Print the sum of all penalties if Arthur completes the PAs in the optimal order.
2 1
2 0
1 0
6
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的更多相关文章
- Delphi项目构成之单元文件PAS
单元文件是Pascal源文件,扩展名为.pas. 有三种类型的单元文件: 窗体/数据模块和框架的单元文件(form/data module and frame units),一般由Delphi自动生成 ...
- Delphi 包的设计思想及它与PAS、BPL、DCU、DLL、OXC的关系。
DCP ,BPL分别是什么文件,起什么作用?你在DELPHI中建立一个package然后保存一下,看看. bpl和Dll比较相似.只是BPL是BORLAND自己弄出来的东西!!!调用也和调用DLL相似 ...
- 5、利用控件TVCLZip和TIdFTP压缩文件并上传到FTP的线程单元pas 改进版
用到临界区 保护写日志的函数: 递归函数 删除目录下的所有文件: 循环创建或判断FTP的目录: 可改进的地方:循环压缩深层次目录的所以文件: 实现断点续传,或断点下载: {************** ...
- F2063 Could not compile used unit 'tt.pas'
install packge error F2063 Could not compile used unit 'tt.pas' 有可能是工程的pas文件相对路径不对.在工程管理看是否能打开文件,如果打 ...
- 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 & ...
- Messages.pas里的消息
一.Windows 消息大全 这张表拷贝自万一兄的帖子:http://www.cnblogs.com/del/archive/2008/02/25/1079970.html 但是我希望自己能把这些消息 ...
- 问题-RZ安装后报错“RzBorder.pas”
错误象现:[Error] RzBorder.pas(1429): Number of elements differs from declaration [Fatal Error] RzEdit.pa ...
- 问题-[致命错误] 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 ...
- 问题-[Delphi]MainFrame.pas(4340): E2036 Variable required
问题现象:写了一个TObjectList的Sort方法,但是写成ObjectList.Sort(@SortBridgeEDOReportQtys); 再F9时提示“E2036 Variable req ...
随机推荐
- IELTS Writing Task 2: 'music' essay
IELTS Writing Task 2: 'music' essay Here's my band 9 sample answer for the question below. Some peop ...
- Sping IOC容器
Sping IOC容器 package servlet; import org.springframework.context.ApplicationContext; import org.sprin ...
- Nacos client 客户端cpu占用100% 问题排查和解决方案
Nacos version:1.1.3client version:1.0.0 dependency: 'org.springframework.cloud:spring-cloud-alibaba- ...
- Spring Schedule 实现定时任务
很多时候我们都需要为系统建立一个定时任务来帮我们做一些事情,SpringBoot 已经帮我们实现好了一个,我们只需要直接使用即可,当然你也可以不用 SpringBoot 自带的定时任务,整合 Quar ...
- 写给想要入门python或者正在入门python的小朋友们
写在前面: 最近好像python挺火,虽然我也在天天写python,但是python毕竟是动态语言,就拿常被人吐槽的java来说,python绝大不多数地方是不如java的.python只能是你的一个 ...
- DoMes平台首页菜单栏
问题1:左侧菜单栏数据是在哪里获取的? 答案1: 项目根目录的Views/Home/Index文件为平台首页 打开Index.cshtml文件,有一个framework-clientdata.js引入 ...
- UITextField的使用、介绍、讲解、全解、简介、说明
[2018年中秋节良心写作]文章将尽可能的全面介绍UITextField的所有相关知识,逻辑连贯,需要认真理解,一气呵成. 关键词: 屏幕键盘(onscreen keyboard).键盘自定义.键盘类 ...
- idea配置使用
1.下载时注意连带下载git 2.实时清除内存 打开 show memory indicator 3.插件安装 前端常用插件(vue,element,css,html,node,ts等)找到适合自己 ...
- redis之List类型常用方法总结
redis之List类型常用方法总结 格式: 存---LPUSH key value [value ...] 取--LRANGE key start stop lpush key value [val ...
- myBatis 操作 mysql时,使用 like 关键进行模糊查询的方法
参考:https://blog.csdn.net/rainbow702/article/details/50519424 like CONCAT('%', #{mkName}, '%')