QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142107#6693. Fast and FatLINTONGRE 1ms3464kbC++141.2kb2023-08-18 14:53:432023-08-18 14:53:45

Judging History

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

  • [2023-08-18 14:53:45]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3464kb
  • [2023-08-18 14:53:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch>'9'||ch<'0'){
        if(ch=='-')w=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=(s<<3)+(s<<1)+ch-'0';
        ch=getchar();
    }
    return s*w;
}
int t,n;
struct tree{
    int v,w,sum;
}tr[1000005];
bool cmp1(tree a,tree b){
    if(a.v!=b.v)return a.v<b.v;
    return a.w<b.w;
}
bool cmp(tree a,tree b){
    if(a.w!=b.w)return a.w>b.w;
    return a.v<b.v;
}
bool cmp2(tree a,tree b){
    if(a.sum!=b.sum)return a.sum>b.sum;
    else return a.v>b.v;
}
int minn;
signed main(){
    t=read();
    while(t--){
        n=read();
        for(int i=1;i<=n;i++){
            tr[i].v=read();
            tr[i].w=read();
            tr[i].sum=tr[i].v+tr[i].w;
        }
        minn=0x3f3f3f3f;
        sort(tr+1,tr+n+1,cmp1);
        sort(tr+1,tr+n/2,cmp);
        sort(tr+n/2+1,tr+n+1,cmp2);
        int mid=n/2;
        for(int i=1;i<=mid;i++){
            minn=min(minn,max(tr[i].v,min(tr[i+mid].sum-tr[i].w,tr[i+mid].v)));
        }
        for(int i=mid+1;i<=n;i++){
            minn=min(minn,tr[i].v);
        }
        cout<<minn<<endl;
    }
}

详细

Test #1:

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

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:

352409014
785434740
330752033
280572174
620790284
960871619
576690224
525403368

result: