QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142125 | #6693. Fast and Fat | LINTONG | WA | 5ms | 19056kb | C++14 | 1.2kb | 2023-08-18 15:23:44 | 2023-08-18 15:24:05 |
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,ans;
struct tree{
int v,w;
}tr[1000005];
bool cmp(tree a,tree b){
if(a.v!=b.v)return a.v<b.v;
return a.w<b.w;
}
bool check(int x){
priority_queue<int>q1,q2;
for(int i=1;i<=n;i++){
if(tr[i].v>=x)q1.push(tr[i].v+tr[i].w-x);
else q2.push(tr[i].w);
}
if(q1.size()<q2.size())return 0;
for(int i=1;i<=q2.size();i++){
int x=q1.top(),y=q2.top();
q1.pop();q2.pop();
if(x<y)return 0;
}
return 1;
}
signed main(){
t=read();
while(t--){
n=read();
ans=1;
memset(tr,0,sizeof(tr));
for(int i=1;i<=n;i++){
tr[i].v=read(),tr[i].w=read();
}
sort(tr+1,tr+n+1,cmp);
int l=1,r=1000000000;
while(l<=r){
int mid=l+r>>1;
if(check(mid))ans=mid,l=mid+1;
else r=mid-1;
}
cout<<ans;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 19056kb
input:
2 5 10 5 1 102 10 100 7 4 9 50 2 1 100 10 1
output:
81
result:
wrong answer 1st numbers differ - expected: '8', found: '81'