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 ...
随机推荐
- 第1节 Scala基础语法:scala中的方法源码分析
val list=List(1,2,3,4) list.reduce((x:Int,y:Int)=>x+y)--->list.reduceLeft((x:Int,y:Int)=>x+ ...
- Activity切换动画。从右边滑入,关闭时从左边滑入
直接贴代码吧 1. 动画文件(两个动画文件配置到res/anim目录下) activity_anim_in_right.xml <?xml version="1.0" e ...
- Android FM模块学习之四源码解析(一)
转自:http://blog.csdn.net/tfslovexizi/article/details/41516149?utm_source=tuicool&utm_medium=refer ...
- [CEOI 2004]锯木厂选址
Description 题库链接 从山顶上到山底下沿着一条直线种植了 \(n\) 棵老树.当地的政府决定把他们砍下来.为了不浪费任何一棵木材,树被砍倒后要运送到锯木厂. 木材只能朝山下运.山脚下有一个 ...
- python--一起来盖个时间戳!!
1.datetime import datetime print(datetime.datetime.now()) 2.time import time otherStyleTime = time.s ...
- Centos7 忘记密码解决方法
一.Centos7 忘记密码解决方法 1.进入单用户模型 重启 Linux 系统主机并出现引导界面时,按下键盘上的 e 键进入内核编辑界面 然后按向下键,找到以“Linux16”开头的行,在该行的最后 ...
- PHP常用的一些优化技巧
PHP常用的一些优化技巧 点击联系老杨 ecshop模板 php 优化技巧 老杨ecshop ecshop二次开发 2013-03-29 0 做为最流行的WEB语言, PHP他的突出优势就是其速度与效 ...
- 认识iOS系统架构
关于本文: 文章主要介绍iOS系统架构中的四层结构的内容.常用的框架.大致的功能,然后对iOS开发人员的发展提出自己的一些拙见. 一.iOS系统是基于UNIX系统,所有从系统稳定性上来说的确比其他操作 ...
- HTML的几个注意点
一.HTML 1.HTML5有哪些新特性?新增的标签有哪些? 新特性: 语义标签——语义化标签使得页面的内容结构化,见名知义 增强型表单——拥有多个新的表单 Input 输入类型.这些新特性提供了更好 ...
- 第1节 kafka消息队列:11、kafka的数据不丢失机制,以及kafka-manager监控工具的使用;12、课程总结
12.kafka如何保证数据的不丢失 12.1生产者如何保证数据的不丢失 kafka的ack机制:在kafka发送数据的时候,每次发送消息都会有一个确认反馈机制,确保消息正常的能够被收到 如果是同步模 ...