题解:P12360 [eJOI 2024] 足球决斗 / CF Duels
显然有但我们知道的信息越多时,我们越能知道我们是否能够获得冠军,满足单调性,所以我们考虑二分答案。
在二分的
#include<bits/stdc++.h>
using namespace std;
#define N 50005
#define intl long long
#define For(i,a,b) for(intl i=a;i<=b;i++)
#define deo(i,a,b) for(intl i=a;i>=b;i--)
intl read() {
intl x=0,k=1;char ch=getchar();
while(!isdigit(ch)) {if(ch == '-') k=-1;ch=getchar();}
while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*k;
}
intl n,p[N],b[N],a[N],sum;
bool check(intl x) {
multiset<intl> qwe,qaz,ys;//要用multiset,因为对方球员的等级可能有相同的,或者您使用优先队列
set<pair<intl,intl>> st;//保存所有体育场的奖金数和对方球员的等级
For(i, 1, n) ys.insert(a[i]);//己方
For(i, 1, x) st.insert({-p[i],b[i]});//确定的体育场
For(i, x+1, n) qwe.insert(-b[i]),qaz.insert(-p[i]);
For(i, x+1, n) st.insert({*qaz.begin(),-*qwe.begin()}),qaz.erase(qaz.begin()),qwe.erase(qwe.begin());//对于不确定的我们按奖金大小分配相应位次的球员
intl res = 0;
for(auto tmp:st){
auto it = ys.upper_bound(tmp.second);
if(it != ys.end()) res += -tmp.first, ys.erase(it);
}
return res > sum/2;//当我们在最坏情况下的奖金数已经大于总奖金的一半时,我们一定可以获得冠军
}
int main() {
n = read();
For(i, 1, n) p[i] = read(), sum += p[i];
For(i, 1, n) b[i] = read();
For(i, 1, n) a[i] = read();
intl l = 0, r = n, ans = -1;
while(l < r) {
intl mid = (l+r)>>1;
if(check(mid)) ans = r = mid;
else l = mid+1;
}
printf("%lld\n",ans);
return 0;
}