QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#183765 | #6693. Fast and Fat | liuzhenhao09# | RE | 1ms | 8188kb | C++20 | 1.5kb | 2023-09-19 20:11:09 | 2023-09-19 20:11:09 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
struct node{
int v,w;
bool operator <(const node& kkk)const{
return v < kkk.v;
}
}a[100010],b[100010],c[100010];
int T,n,tot1 = 0,tot2 = 0;
bool cmp1(node A,node B){
return A.w > B.w;
}
bool cmp2(node A,node B){
return A.w + A.v < B.w + B.v;
}
bool check(int x){
tot1 = tot2 = 0;
for(int i = 1; i <= n; i++){
if(a[i].v < x) b[++tot1] = a[i];
else c[++tot2] = a[i];
}
sort(b + 1,b + tot1 + 1,cmp1);
sort(c + 1,c + tot2 + 1,cmp2);
multiset<pii>s;
multiset<int>t;
multiset<pii>::iterator it;
multiset<int>::iterator ti;
for(int i = 1; i <= tot2; i++) s.insert(make_pair(c[i].w,c[i].v + c[i].w)),t.insert(c[i].v + c[i].w);
if(tot1 > tot2) return 0;
for(int i = 1; i <= tot1; i++){
if(s.empty()) return 0;
it = s.lower_bound(make_pair(b[i].w,0));
if(it != s.end()){
int v = it->second;
t.erase(t.find(v));
s.erase(it);
}
else{
if(t.empty()) return 0;
ti = t.end();
ti--;
if((*ti) - b[i].w < x) return 0;
t.erase(ti);
}
}
return 1;
}
signed main(){
scanf("%lld",&T);
while(T--){
scanf("%lld",&n);
int mx = 0;
for(int i = 1; i <= n; i++) scanf("%lld %lld",&a[i].v,&a[i].w),mx = max(mx,a[i].v);
sort(a + 1,a + n + 1);
int l = 1,r = mx;
while(l < r){
int mid = (l + r + 1) >> 1;
if(check(mid)) l = mid;
else r = mid - 1;
}
printf("%lld\n",l);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 8188kb
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...