NOI Contest Archive

Archive / 2020 / July 2020

Delete the Binary String

Medium · National Olympiad in Informatics Sri Lanka - July 2020

You are given a string of length N and an array A of size N, numbered from 1 to N. String only has ‘1’s and ‘0’s.

You should do the following operations until the string becomes empty.

Select a part from the string such that all characters are the same and delete that part. Then reconnect the remaining parts of the string without changing the order.

You will get Ax points for deleting part of length x from the string. Your task is to maximize the points you can get.

Input Format

Output Format

Constraints

Sample Input 0

7
1101001
4 5 10 101 2 3 4

Sample Output 0

113