There are N schedules, the i-th schedule has start time si and end time ei (1 <= i <= N). There are some machines. Each two overlapping schedules cannot be performed in the same machine. For each machine the working time is defined as the difference between timeend and timestart , where time_{end} is time to turn off the machine and timestart is time to turn on the machine. We assume that the machine cannot be turned off between the timestart and the timeend.

Print the minimum number K of the machines for performing all schedules, and when only uses K machines, print the minimum sum of all working times.

Input

The first line contains an integer T (1 <= T <= 100), the number of test cases. Each case begins with a line containing one integer N (0 < N <= 100000). Each of the next N lines contains two integers si and ei (0<=si<ei<=1e9).

Output

For each test case, print the minimum possible number of machines and the minimum sum of all working times.

Sample Input

1

3

1 3

4 6

2 5

Sample Output

2 8

题意:



思路:



先把每一个任务按照起始时间排序,然后用一个multiset维护每一个机器在做任务的终止时间,

对于每一个任务,我们去multiset中去二分找是否有一个机器的任务终止时间在当前任务开始时间之前(或等于)。

如果有,就在那个机器中执行该任务,否则就创建一个新机器。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int t;
struct node
{
int l, r; } a[maxn];
bool cmp(node &aa, node &bb)
{
// if(aa.r!=bb.r)
// return aa.r<bb.r;
// else
return aa.l < bb.l;
}
int n;
multiset<int> st;
ll ans = 0ll;
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\code_stream\\out.txt","w",stdout); gg(t);
while (t--)
{
gg(n);
repd(i, 1, n)
{
gg(a[i].l);
gg(a[i].r);
}
sort(a + 1, a + 1 + n, cmp);
st.clear();
ans = a[1].r - a[1].l;
st.insert(a[1].r);
repd(i, 2, n)
{
auto it = st.upper_bound(a[i].l);
if (it == st.begin())
{
st.insert(a[i].r);
ans += a[i].r - a[i].l; } else
{
it--; ans += a[i].r - (*it);
st.erase(it);
st.insert(a[i].r); }
}
cout << sz(st) << " " << ans << endl;
} return 0;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

Schedule HDU - 6180 (multiset , 贪心)的更多相关文章

  1. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

  2. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  3. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  4. 2017多校第10场 HDU 6180 Schedule 贪心,multiset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...

  5. HDU - 6180:Schedule(简单贪心)

    There are N schedules, the i-th schedule has start time s i  si and end time e i  ei (1 <= i < ...

  6. hdu 6180 Schedule

    Schedule Problem Description There are N schedules, the i-th schedule has start time si and end time ...

  7. hdu 6180贪心

    题意:有m个工程,一台机器在同一时间只能运行一个工程,告诉你每个工程的起始时间和结束时间,求出最少要多少个机器以及最小的机器总运行时间(机器开始了就不能停了,直到用完该台机器才停止). 题解:由于这里 ...

  8. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  9. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

随机推荐

  1. Oracle JET mobile cordove navigator.app对象

    在使用 Oracle JET 开发 webapp 时,会使用到 ojrouter ,ojrouter 默认含有历史记录推送功能.在调试 Android 时会发现返回键总是返回到上一次浏览记录(App ...

  2. Detectron系统实现了最先进的物体检测算法https://github.com/facebookresearch/Detectron

    ,包括Mask R-CNN. 它是用Python编写的,支持Caffe2深度学习框架. 不久前,FAIR才开源了语音识别的工具wav2letter,戳这里看大数据文摘介绍<快讯 | Facebo ...

  3. 微信小程序 API 数据缓存

    微信小程序 数据缓存 (类似于 cookie) wx.setStorage() 将数据存储在本地缓存中制定的 key 中.会覆盖掉原来该 key 对应的内容,数据存储生命周期跟小程序本身一致,即除用户 ...

  4. lr参数与C语言函数参数的区别

    C变量不能再lr函数中使用: c变量必须定义在lr函数之前: LR参数可以在LR函数中直接当做字符串使用. LR参数是lr自己封装的一个钟对象, LR参数的表达方式:{ParamName}

  5. [C#菜鸟]C# Hook (一)

    转过来的文章,出处已经不知道了,但只这篇步骤比较清晰,就贴出来了. 一.写在最前 本文的内容只想以最通俗的语言说明钩子的使用方法,具体到钩子的详细介绍可以参照下面的网址: http://www.mic ...

  6. 二、Jmter查看结果数只能显示有限的数据,查看全部数据

    1.打开jmeter安装目录,找到bin目录下jmeter.properties文件 2.搜索:view.results.tree.max_size=10485760 3.将#号去掉,重启jmeter

  7. CAN诊断学习

    汽车CAN总线有动力总成PCAN,底盘控制CCAN,整车控制BCAN,娱乐ECAN,诊断DCAN五种. CAN诊断,即是对CAN网络中各节点,各CAN总线,网关的故障进行检查与修复. 统一诊断服务(U ...

  8. leetcode 4寻找两个有序数组的中位数

    最优解O(log(min(m,n))) /** 之前用合并有序数组的思想做了O((m+n+1)/2),现在试一试O(log(min(m,n))) 基本思路为:通过二分查找较小的数组得到对应的中位数(假 ...

  9. WPF DevExpress Chart控件 需要引用的类库

    DevExpress.Charts.v16.1.Core.dll DevExpress.Data.v16.1.dll DevExpress.Mvvm.v16.1.dll DevExpress.Xpf. ...

  10. delphi 进程通讯之WM_COPYDATA 发送程序(SendData.exe) 可用

    http://www.delphitop.com/html/wangluo/1529.html delphi 进程通讯之WM_COPYDATA 发送程序(SendData.exe) 作者:admin ...