QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380988#6693. Fast and FatSSHL#WA 52ms3576kbC++141.3kb2024-04-07 15:57:132024-04-07 15:57:14

Judging History

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

  • [2024-04-07 15:57:14]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:3576kb
  • [2024-04-07 15:57:13]
  • 提交

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[n/2].first,l=a[n-1].first;
    // 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;
}

详细

Test #1:

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

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
Wrong Answer
time: 52ms
memory: 3576kb

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:

280251502
785434740
330752033
280572174
704877362
220052258
576690224
525403368
136979645
399988835
610497257
558155454
630818264
287404882
370430730
526259135
781258283
447215199
300930080
419192366
431930706
479323438
448268710
391912906
613609546
467782812
457987604
389750718
447390353
696516804
...

result:

wrong answer 1st numbers differ - expected: '352409014', found: '280251502'