-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
49 lines (46 loc) · 1.1 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[200005];
int main()
{
fastio;
long long n,i;
vector<long long> child,adult;
string s;
cin>>n;
cin>>s;
for(i=0;i<n;i++)
{
cin>>ara[i];
if(s[i]=='0')
child.push_back(ara[i]);
else
adult.push_back(ara[i]);
}
sort(child.begin(),child.end());
sort(adult.begin(),adult.end());
vector<long long>::iterator lower, upper;
long long mx=INT_MIN,cnt=0LL;
for(i=0;i<n;i++)
{
cnt=0;
long long temp;
if(s[i]=='0')
temp=ara[i]+1;
else
temp=ara[i];
lower = lower_bound(child.begin(), child.end(), temp);
upper = lower_bound(adult.begin(), adult.end(), temp);
if(lower==child.end())
cnt+=child.size();
else
cnt+=(lower-child.begin());
if(upper!=adult.end())
cnt+=adult.size()-(upper-adult.begin());
mx=max(mx,cnt);
}
cout<<mx<<"\n";
return 0;
}