QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398610#6693. Fast and FatxiaoleTL 1ms3632kbC++231.2kb2024-04-25 15:41:002024-04-25 15:41:01

Judging History

你现在查看的是最新测评结果

  • [2024-04-25 15:41:01]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3632kb
  • [2024-04-25 15:41:00]
  • 提交

answer

 #pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 1e5+9;const ll MOD = 1e9 + 7;
vector<PLL> a;ll n;
bool cmp(PLL l,PLL r){
	if(l.first==r.first) return l.second<r.second;
	else return l.first<r.first;
}
struct cmp2
{
	bool operator()(PLL a,PLL b){
		return a.second>b.second;
	}
};

bool check(ll x){
	priority_queue<PLL,vector<PLL>,cmp2> q;
	for (ll i = 0; i < n; i++)
	{
		if(a[i].first<x) q.push({a[i]});
		else if(q.size() and a[i].first-(q.top().second-a[i].second)>=x) q.pop();
	}
	if(q.size()) return false;
	else return true;
}
void solve(){
   cin>>n;ll ma=MIN,mi=MAX;
	for (ll i = 0; i < n; i++)
	{
		ll o,p;cin>>o>>p;
		ma=max(ma,o);
		mi=min(mi,o);
		a.push_back({o,p});
	}
	sort(a.begin(),a.end(),cmp);
	ll l=mi,r=ma;ll ans=0;
	while(l<=r){
		ll mid=(l+r)/2;
		if(check(mid)) {
			l=mid+1;ans=mid;
		}else r=mid-1;
	}
	cout<<ans<<"\n";
}
int main(){
	ios;ll _=1;cin>>_;
	while (_--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3632kb

input:

2
5
10 5
1 102
10 100
7 4
9 50
2
1 100
10 1

output:

8
1

result:

ok 2 number(s): "8 1"

Test #2:

score: -100
Time Limit Exceeded

input:

10000
4
280251502 664541723
375808746 641141991
95134537 898607509
455259328 944978891
2
798417052 547329847
785434740 991778535
6
623628702 857611223
275667427 453747403
292209526 283132767
330752033 988721243
470297536 608192332
477186035 325224271
3
280572174 994054447
306566740 923535026
3781360...

output:


result: