考虑两个任务 \(1\) 和 \(2\),当前时间为 \(T\),两个任务都要完成。

先完成任务 \(1\) 的条件是 \(T>t_1\) 且 \(T+b_1>t_2\),先完成任务 \(2\) 的条件是 \(T>t_2\) 且 \(T+b_2>t_1\)。

移项,\(T>t_2-b_1\) 和 \(T>t_1-b_2\)。

假设先完成任务 \(1\) 的条件更松

那么有 \(t_2-b_1<t_1-b_2\),即 \(t_1+b_1>t_2+b_2\)。

我们观察到这个东西显然满足传递性和严格弱序,所以按这个比较函数排序即可。

时间复杂度 \(O\left(Zn\log n\right)\)。

code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,x,y)for(i=x;i<=(y);i++)
struct task
{
int t,b;
}a[100005];
int read()
{
int A;
bool K;
char C;
C=A=K=0;
while(C<'0'||C>'9')K|=C=='-',C=getchar();
while(C>'/'&&C<':')A=(A<<3)+(A<<1)+(C^48),C=getchar();
return(K?-A:A);
}
inline bool cmp(task _,task __)
{
return _.t+_.b>__.t+__.b;
}
int main()
{
ll t;
int z,n,i;
z=read();
while(z--)
{
n=read(),t=read();
For(i,1,n)a[i].t=read(),a[i].b=read();
sort(a+1,a+n+1,cmp);
For(i,1,n)
{
if(a[i].t>=t)break;
else t+=a[i].b;
if(t<=0)break;
}
puts((i>n?"+1s":"-1s"));
}
return 0;
}

最新文章

  1. [Machine Learning] 国外程序员整理的机器学习资源大全
  2. MAGENTA: Meta-Analysis Gene-set Enrichment of variaNT Associations
  3. 踏着前人的脚印学Hadoop&mdash;&mdash;RPC源码
  4. CDH 不能监控hadoop状态
  5. Centos环境下部署游戏服务器-iptables
  6. POJ 2778 DNA Sequence (AC自动机,矩阵乘法)
  7. Spring 整合hibernante 错误java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
  8. tcpdump抓取HTTP包【转载】
  9. [Vue] vue跳转外部链接
  10. text-decoration、text-decoration-color、text-decoration-line、text-decoration-style属性
  11. C语言 16进制与ascii码互转
  12. Template模板
  13. [Leetcode 78]求子集 Subset
  14. Java 获取当前项目所在服务器的 IP 地址
  15. md5加密解密版本2
  16. screen基本用法
  17. 初识Shell与Shell脚本
  18. subline 自己使用的插件
  19. winform,listbox设置行高
  20. 生活类App原型制作分享-AnyList

热门文章

  1. 蒲公英 &#183; JELLY技术周刊 Vol 27: 平平无奇 React 17
  2. AngularJS——ui-router
  3. FFmpeg滤镜使用
  4. git的远程分支是干啥的,和本地的有什么区别?
  5. CSS动画之过渡模块
  6. Java学习的第十七天
  7. Redis还可以做哪些事?
  8. 分四个阶段学习python并找到一份好工作
  9. Route53导出解析记录
  10. 5分钟GET我使用Github 5 年总结的这些骚操作!