QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398610 | #6693. Fast and Fat | xiaole | TL | 1ms | 3632kb | C++23 | 1.2kb | 2024-04-25 15:41:00 | 2024-04-25 15:41:01 |
Judging History
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;
}
詳細信息
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...