#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
void solve() {
int n; cin >> n;
vector<int> slot;
set<int> ppl;
for(int i=0,k;i<n;i++) {
cin >> k; if(k) slot.push_back(i);
}
for(int i=0,k;i<n;i++) {
cin >> k; if(k) ppl.insert(i);
}
// cout << "slot: ";
// for(auto s : slot) cout << s << ' ';
// cout << endl;
// cout << "ppl: ";
// for(auto s : ppl) cout << s << ' ';
// cout << endl;
vector<bool> filled(slot.size());
int ans = 0;
for(int i=0;i<(int)slot.size();i++){
auto ptr = ppl.upper_bound(slot[i]);
if(ptr != ppl.end()) {
ans++; filled[i] = true;
// cout << "fill " << slot[i] << " with " << *ptr << endl;
ppl.erase(ptr);
}
}
for(int i=0;i<(int)slot.size();i++){
if(filled[i]) continue;
if(ppl.count(slot[i])) {
ppl.erase(slot[i]);
filled[i] = true;
}
}
cout << ans - ppl.size() << endl;
}
int main(){
int tc = 1;
while(tc--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |