#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, a[maxn], c[maxn];
bool check(int x){
multiset<int> s1, s2;
for (int i = 1; i <= n; ++i){
if(c[i]&&s2.empty()){
s1.insert(a[i]);
}else if(c[i]==0&&s1.empty()){
s2.insert(a[i]);
}else{
if(c[i]==0){
if(s1.lower_bound(x-a[i])==s1.end()){
return false;
}else{
s1.erase(s1.lower_bound(x - a[i]));
}
}else{
if(s2.lower_bound(x-a[i])==s2.end()){
return false;
}else{
s2.erase(s2.lower_bound(x - a[i]));
}
}
}
}
return true;
}
signed main(){
cin >> n;
for (int i = 1; i <= n; ++i){
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; ++i){
scanf("%d", &c[i]);
}
int l = 0, r = 2e8 + 5;
while(l<r){
int mid = (l + r+1) / 2;
if(check(mid))
l = mid;
else
r = mid - 1;
}
cout << r << "\n";
return 0;
}
2024 江苏省大学生程序设计大赛i题
最新推荐文章于 2024-07-25 11:44:32 发布