CF1895G.Two Characters, Two Colors

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string consisting of characters 0 and/or 1. You have to paint every character of this string into one of two colors, red or blue.

If you paint the ii -th character red, you get rir_i coins. If you paint it blue, you get bib_i coins.

After coloring the string, you remove every blue character from it, and count the number of inversions in the resulting string (i. e. the number of pairs of characters such that the left character in the pair is 1, and the right character in the pair is 0). For each inversion, you have to pay 11 coin.

What is the maximum number of coins you can earn?

输入格式

The first line of the input contains one integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

Each test case consists of four lines:

  • the first line contains one integer nn ( 1n41051 \le n \le 4 \cdot 10^5 ) — the length of the string;
  • the second line contains ss — a string of nn characters, where each character is either 0 or 1;
  • the third line contains nn integers r1,r2,,rnr_1, r_2, \dots, r_n ( 1ri10121 \le r_i \le 10^{12} );
  • the fourth line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n ( 1bi10121 \le b_i \le 10^{12} ).

Additional constraint on the input: the sum of values of nn over all test cases does not exceed 41054 \cdot 10^5 .

输出格式

For each test case, print one integer — the maximum number of coins you can earn.

输入输出样例

  • 输入#1

    4
    7
    0100010
    6 6 6 7 7 6 6
    3 3 5 4 7 6 7
    5
    10111
    9 8 5 7 5
    4 4 7 8 4
    10
    0100000000
    7 7 6 5 2 2 5 3 8 3
    8 6 9 6 6 8 9 7 7 9
    8
    01010000
    8 7 7 7 8 7 7 8
    4 4 4 2 1 4 4 4

    输出#1

    43
    36
    76
    52

说明/提示

Explanations for the test cases for the example (blue characters are underlined, red ones are not):

  1. 01000100100\underline{0}1\underline{0} ;
  2. 1011110\underline{11}1 ;
  3. 0100000000\underline{0}1\underline{00000000} ;
  4. 010100000\underline{1}010000 .
首页