QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142107 | #6693. Fast and Fat | LINTONG | RE | 1ms | 3464kb | C++14 | 1.2kb | 2023-08-18 14:53:43 | 2023-08-18 14:53:45 |
Judging History
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;
}
}
Details
Tip: Click on the bar to expand more detailed information
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