QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142138 | #6693. Fast and Fat | LINTONG | WA | 1ms | 3472kb | C++14 | 1.2kb | 2023-08-18 15:34:51 | 2023-08-18 15:34:51 |
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;
for(int i=1;i<=n;i++){
tr[i].v=read(),tr[i].w=read();
}
int l=1,r=1e18;
while(l<=r){
int mid=l+r>>1;
if(check(mid))ans=mid,l=mid+1;
else r=mid-1;
}
cout<<l<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3472kb
input:
2 5 10 5 1 102 10 100 7 4 9 50 2 1 100 10 1
output:
9 2
result:
wrong answer 1st numbers differ - expected: '8', found: '9'