#abc257c. C - Robot Takahashi

C - Robot Takahashi

Score : 300300 points

问题描述

设有 NN 个人,每个人要么是儿童要么是成年人。第 ii 个人的体重为 WiW_i

每个人是儿童还是成年人的信息由一个长度为 NN 的字符串 SS 给出,该字符串仅包含字符 01。如果字符串 SS 的第 ii 个字符为 0,则表示第 ii 个人是儿童;若为 1,则表示第 ii 个人是成年人。

当给机器人高桥一个实数 XX 时,高桥会按照以下规则判断:体重小于 XX 的人被判断为儿童,体重大于等于 XX 的人被判断为成年人。

对于一个实数值 XX,令 f(X)f(X) 表示高桥正确判断儿童或成年人人数的数量。

找出所有实数 XX 中,f(X)f(X) 的最大值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN people, each of whom is either a child or an adult. The ii-th person has a weight of WiW_i.
Whether each person is a child or an adult is specified by a string SS of length NN consisting of 0 and 1.
If the ii-th character of SS is 0, then the ii-th person is a child; if it is 1, then the ii-th person is an adult.

When Takahashi the robot is given a real number XX, Takahashi judges a person with a weight less than XX to be a child and a person with a weight more than or equal to XX to be an adult.
For a real value XX, let f(X)f(X) be the number of people whom Takahashi correctly judges whether they are children or adults.

Find the maximum value of f(X)f(X) for all real values of XX.

Constraints

  • 1N2×1051\leq N\leq 2\times 10^5
  • SS is a string of length NN consisting of 0 and 1.
  • 1Wi1091\leq W_i\leq 10^9
  • NN and WiW_i are integers.

Input

Input is given from Standard Input in the following format:

NN

SS

W1W_1 W2W_2 \ldots WNW_N

Output

Print the maximum value of f(X)f(X) as an integer in a single line.

Sample Input 1

5
10101
60 45 30 40 80

Sample Output 1

4

When Takahashi is given X=50X=50, it judges the 22-nd, 33-rd, and 44-th people to be children and the 11-st and 55-th to be adults.
In reality, the 22-nd and 44-th are children, and the 11-st, 33-rd, and 55-th are adults, so the 11-st, 22-nd, 44-th, and 55-th people are correctly judged. Thus, f(50)=4f(50)=4.

This is the maximum since there is no XX that judges correctly for all 55 people. Thus, 44 should be printed.

Sample Input 2

3
000
1 2 3

Sample Output 2

3

For example, X=10X=10 achieves the maximum value f(10)=3f(10)=3.
Note that the people may be all children or all adults.

Sample Input 3

5
10101
60 50 50 50 60

Sample Output 3

4

For example, X=55X=55 achieves the maximum value f(55)=4f(55)=4.
Note that there may be multiple people with the same weight.

update @ 2024/3/10 10:55:14

}