CF1895G.Two Characters, Two Colors
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:512MB
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 i-th character red, you get ri coins. If you paint it blue, you get bi 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 1 coin.
What is the maximum number of coins you can earn?
给你一个仅由字符 0 和/或 1 组成的字符串。你需要将该字符串的每个字符涂成两种颜色之一:红色或蓝色。
若将第 i 个字符涂成红色,则获得 ri 枚硬币;若涂成蓝色,则获得 bi 枚硬币。
完成着色后,你将字符串中所有蓝色字符移除,并统计剩余字符串中的逆序对数量(即满足“左侧字符为 1、右侧字符为 0”的字符对的个数)。对每个逆序对,你需要支付 1 枚硬币。
你最多能获得多少枚硬币?
输入格式
The first line of the input contains one integer t (1≤t≤104) — the number of test cases.
Each test case consists of four lines:
- the first line contains one integer n (1≤n≤4⋅105) — the length of the string;
- the second line contains s — a string of n characters, where each character is either 0 or 1;
- the third line contains n integers r1,r2,…,rn (1≤ri≤1012);
- the fourth line contains n integers b1,b2,…,bn (1≤bi≤1012).
Additional constraint on the input: the sum of values of n over all test cases does not exceed 4⋅105.
输入的第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例由四行组成:
- 第一行包含一个整数 n(1≤n≤4⋅105)—— 字符串的长度;
- 第二行包含字符串 s —— 一个长度为 n 的字符串,其中每个字符均为
0或1; - 第三行包含 n 个整数 r1,r2,…,rn(1≤ri≤1012);
- 第四行包含 n 个整数 b1,b2,…,bn(1≤bi≤1012)。
输入的额外约束:所有测试用例的 n 值之和不超过 4⋅105。
输出格式
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):
- 0100010;
- 10111;
- 0100000000;
- 01010000.
示例测试用例的解释(蓝色字符带下划线,红色字符不带下划线):
- 0100010;
- 10111;
- 0100000000;
- 01010000。
输入解题思路,AI测评打分。不知道怎么写?