#P10715. 【MX-X1-T3】「KDOI-05」简单的序列问题

    ID: 11676 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DPO2优化前缀和梦熊比赛

【MX-X1-T3】「KDOI-05」简单的序列问题

Background

Original link: https://oier.team/problems/X1C.

Problem Description

Given a sequence aa of length nn. Define its prefix sum array bi=j=1iajb_i=\sum_{j=1}^i a_j. Define its value S=i=1n(bimod2)S=\sum_{i=1}^n (b_i \bmod 2).

You may perform the following operation on sequence aa any number of times:

  • Swap aia_i and aja_j, costing (ci+cj)(c_i+c_j) yuan, where cc is a given sequence.

For i=0ni=0\sim n, find the minimum cost to make S=iS=i. If it is impossible, output 1-1.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, the number of test cases.

For each test case:

The first line contains a positive integer nn, the length of the sequence.

The second line contains nn positive integers, the sequence aa.

The third line contains nn positive integers, the sequence cc.

Output Format

For each test case:

Output one line with n+1n+1 integers. The ii-th integer denotes the minimum cost to make S=i1S=i-1. If it is impossible, output 1-1.

3
3
1 2 3
1 1 1
5
1 2 3 4 5
2 5 3 6 4
10
1 8 3 5 2 6 3 4 6 2
3 2 7 1 8 2 5 8 3 1
-1 2 0 -1
-1 -1 7 0 9 -1
-1 -1 5 3 4 0 7 8 6 -1 -1

Hint

[Sample Explanation]

For the first test case, initially i=1n(bimod2)=2\sum_{i=1}^n (b_i \bmod 2)=2, so the minimum cost to make S=2S=2 is 00 yuan.

Swapping a1a_1 and a2a_2 makes i=1n(bimod2)=1\sum_{i=1}^n (b_i \bmod 2)=1, so making S=1S=1 can cost 22 yuan. It can be proven that this is optimal.

It can be proven that there is no swapping plan that makes S=0S=0 or S=3S=3.

[Constraints]

This problem uses bundled testdata.

Subtask ID Score nn\leq n\sum n\leq Special Property
11 1010 55 5050 None
22 500500 At most 33 odd numbers in aa
33 1515 3030 150150 None
44 2525 100100 500500
55 1010 500500 ci=1c_i=1
66 3030 None

For 100%100\% of the testdata: 1n,n5001\leq n,\sum n\leq 500, 1ai1091\leq a_i\leq 10^9, 1ci1061\leq c_i\leq 10^6, 1T5001\leq T\leq 500.

Translated by ChatGPT 5