AT_ndpc2026_f.Set
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation P=(P1,P2,…,PN) of (1,2,…,N) and an integer array A1,A2,…,AN of length N.
A subset S of the set {1,2,…,N} is called a good set if it satisfies the following condition:
- For every pair of integers (x,y) such that x<y and x,y∈S, the following holds:
- Let z be the integer such that Pz=min(Px,Px+1,…,Py). (Such a z is uniquely determined.) Then, it must hold that z∈S.
The cost of a good set S is defined as i∈S∑Ai.
For each K=1,2,…,N, find the minimum possible cost among all good sets of size K.
You are given T test cases. Solve each of them.
给你一个 (1,2,…,N) 的排列 P=(P1,P2,…,PN) 和一个长度为 N 的整数数组 A1,A2,…,AN。
集合 {1,2,…,N} 的子集 S 被称为好集合,当且仅当它满足以下条件:
- 对于任意满足 x<y 且 x,y∈S 的整数对 (x,y),以下成立:
- 设 z 是满足 Pz=min(Px,Px+1,…,Py) 的整数。(这样的 z 是唯一确定的。)则必须有 z∈S。
好集合 S 的代价定义为 i∈S∑Ai。
对每个 K=1,2,…,N,求所有大小为 K 的好集合中可能的最小代价。
你将得到 T 组测试数据。请分别求解每组数据。
输入格式
The input is given from standard input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N
P1 P2 … PN
A1 A2 … AN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例按以下格式给出:
N
P1 P2 … PN
A1 A2 … AN
输出格式
Print T lines. For the i-th line, output the answer for the i-th test case.
For each test case, output the answers for K=1,2,…,N in one line, separated by spaces.
输出 T 行。对于第 i 行,输出第 i 个测试用例的答案。
对于每个测试用例,在一行内输出 K=1,2,…,N 对应的答案,各答案之间用空格分隔。
输入输出样例
输入#1
3 4 4 1 2 3 1 8 2 4 6 5 3 2 4 6 1 73 38 30 85 27 45 10 4 10 3 7 2 6 8 9 5 1 853822501 687675302 281611653 844033520 423210108 339630584 780395612 207907746 285523486 359061085
输出#1
1 6 11 15 27 57 95 140 213 298 207907746 493431232 833061816 1192122901 1537883577 1896944662 2584619964 3365015576 4209049096 5062871597
说明/提示
Sample 1 Explanation:
In the first test case:
- For K=1, S={1} is optimal,
- For K=2, S={3,4} is optimal,
- For K=3, S={1,2,3} is optimal,
- For K=4, S={1,2,3,4} is optimal.
Constraints
- 1≤T≤5000
- 1≤N≤5000
- 1≤Ai≤109
- (P1,P2,…,PN) is a permutation of (1,2,…,N)
- The sum of N over all test cases is at most 5000
- All input values are integers
样例 1 解释:
在第一个测试用例中:
- 当 K=1 时,最优集合为 S={1};
- 当 K=2 时,最优集合为 S={3,4};
- 当 K=3 时,最优集合为 S={1,2,3};
- 当 K=4 时,最优集合为 S={1,2,3,4}。
约束条件
- 1≤T≤5000
- 1≤N≤5000
- 1≤Ai≤109
- (P1,P2,…,PN) 是 (1,2,…,N) 的一个排列;
- 所有测试用例的 N 之和不超过 5000;
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?