#abc257c. C - Robot Takahashi
C - Robot Takahashi
Score : points
问题描述
设有 个人,每个人要么是儿童要么是成年人。第 个人的体重为 。
每个人是儿童还是成年人的信息由一个长度为 的字符串 给出,该字符串仅包含字符 0
和 1
。如果字符串 的第 个字符为 0
,则表示第 个人是儿童;若为 1
,则表示第 个人是成年人。
当给机器人高桥一个实数 时,高桥会按照以下规则判断:体重小于 的人被判断为儿童,体重大于等于 的人被判断为成年人。
对于一个实数值 ,令 表示高桥正确判断儿童或成年人人数的数量。
找出所有实数 中, 的最大值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are people, each of whom is either a child or an adult. The -th person has a weight of .
Whether each person is a child or an adult is specified by a string of length consisting of 0
and 1
.
If the -th character of is 0
, then the -th person is a child; if it is 1
, then the -th person is an adult.
When Takahashi the robot is given a real number , Takahashi judges a person with a weight less than to be a child and a person with a weight more than or equal to to be an adult.
For a real value , let be the number of people whom Takahashi correctly judges whether they are children or adults.
Find the maximum value of for all real values of .
Constraints
- is a string of length consisting of
0
and1
. - and are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum value of 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 , it judges the -nd, -rd, and -th people to be children and the -st and -th to be adults.
In reality, the -nd and -th are children, and the -st, -rd, and -th are adults, so the -st, -nd, -th, and -th people are correctly judged. Thus, .
This is the maximum since there is no that judges correctly for all people. Thus, should be printed.
Sample Input 2
3
000
1 2 3
Sample Output 2
3
For example, achieves the maximum value .
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, achieves the maximum value .
Note that there may be multiple people with the same weight.
update @ 2024/3/10 10:55:14