QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#381013#6693. Fast and FatSSHL#RE 1ms3628kbC++141.3kb2024-04-07 16:02:462024-04-07 16:02:47

Judging History

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

  • [2024-04-07 16:02:47]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3628kb
  • [2024-04-07 16:02:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template <class T> using P=pair<T,T>;
vector<P<int>> a;
int n;
bool check(int x)
{
    vector<int> t,s;
    for(int i=n-1;i>=0;i--)
    {
        if(a[i].first<x)
        t.push_back(a[i].second);
        else s.push_back(a[i].first+a[i].second);
    }
    sort(t.begin(),t.end());
    sort(s.begin(),s.end());
    for(int i=0,j=0;j<s.size();)
    {
        // cout<<s[j]<<' '<<t[i]<<'\n';
        if(s[j]>=t[i]+x)
        i++,j++;
        else j++;
        if(i==t.size())
        return true;
    }
    return false;
}
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        a.push_back({x,y});
    }
    sort(a.begin(),a.end(),[](P<int> a,P<int> b){if(a.first!=b.first) return a.first>b.first;else return a.second>b.second;});
    int r=a[0].first,l=1;
    // for(auto &i:a)
    // cout<<i.first<<' '<<i.second<<'\n';
    while(l<r)
    {
        // cout<<'\n';
        // cout<<l<<' '<<r<<'\n';
        int mid=(r+l+1)/2;
        if(check(mid))
        l=mid;
        else r=mid-1;
    }
    cout<<l<<'\n';
    a.clear();
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
    while(t--)
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Runtime Error

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: