思路就是前缀和来维护 [1,i] 区间的 0,1 个数。
那答案就是 qzh[i][0]+qzh[n][1]−qzh[i][1]。
求 hack。
int qzh[N][2], ans;
struct Node {
int w, male;
bool operator < (const Node &x) const {
return w < x.w;
}
}a[N];
signed main()
{
int n = read();
for(int i = 1; i <= n; i++) scanf("%1lld", &a[i].male);
for(int i = 1; i <= n; i++) scanf("%lld", &a[i].w);
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++) {
if(a[i].male == 1) qzh[i][1] = qzh[i - 1][1] + 1, qzh[i][0] = qzh[i - 1][0];
else qzh[i][1] = qzh[i - 1][1], qzh[i][0] = qzh[i - 1][0] + 1;
}
for(int i = 1; i <= n; i++) {
if(a[i].w == a[i + 1].w) continue;
ans = max(ans, qzh[i][0] + qzh[n][1] - qzh[i][1]);
}
cout << ans;
return 0;
}