这题怎么怎么看怎么水啊??
很明显的贪心思路,就是数据看上去有点大..
没有比赛打的我,非常废物了.
/* xzppp */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAXM = 1e5+17;
const int MAXN = 1e5+17;
struct dap
{
int s,t,n,k;
dap(int a,int b,int c,int d):s(a),t(b),n(c),k(d){}
dap(){}
bool operator<(const dap & b) const
{
if(n==b.n)
return k>b.k;
return n<b.n;
}
}all[2*MAXN];
int main(int argc, char const *argv[])
{
#ifdef GoodbyeMonkeyKing
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
priority_queue<int > q;
for (int i = 0; i < n; ++i)
{
int s,t;
scanf("%d%d",&s,&t);
all[i] = dap(s,t,s,0);
all[n+i] = dap(s,t,t,1);
}
sort(all, all+2*n);
LL num = 0,sum = 0;
for (int i = 0; i < 2*n; ++i)
{
if(all[i].k)
q.push(all[i].n);
else
{
if(q.empty())
{
num++;
sum += (all[i].t-all[i].s);
}
else
{
sum += (all[i].t-q.top());
q.pop();
}
}
}
cout<<num<<" "<<sum<<endl;
}
return 0;
}