CF1144B.Parity Alternated Deletions
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n−1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
- If it is the first move, he chooses any element and deletes it;
- If it is the second or any next move:
- if the last deleted element was odd, Polycarp chooses any even element and deletes it;
- if the last deleted element was even, Polycarp chooses any odd element and deletes it.
- If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Polycarp 有一个由 n 个整数组成的数组 a。
他想用这个数组来玩一个游戏。游戏由若干轮操作组成。在第一轮操作中,他任选一个元素并将其删除(第一轮操作后,数组中剩余 n−1 个元素)。在后续每一轮操作中,他仍可任选一个元素,但需满足唯一限制:所选元素的奇偶性必须与上一轮被删除元素的奇偶性不同。换言之,被删除元素的奇偶性必须交替出现(偶-奇-偶-奇-… 或 奇-偶-奇-偶-…)。当 Polycarp 无法再进行任何操作时,游戏结束。
形式化地定义如下:
- 若为第一轮操作,他任选一个元素并将其删除;
- 若为第二轮或之后的任意一轮操作:
- 若上一轮被删除的元素为奇数,则 Polycarp 必须任选一个偶数并将其删除;
- 若上一轮被删除的元素为偶数,则 Polycarp 必须任选一个奇数并将其删除。
- 若某轮操作后 Polycarp 无法再执行任何操作,则游戏终止。
Polycarp 的目标是使游戏结束后数组中未被删除的元素之和尽可能小。若 Polycarp 能够将整个数组全部删除,则未被删除元素之和为零。
请帮助 Polycarp 找出该最小可能值。
输入格式
The first line of the input contains one integer n (1≤n≤2000) — the number of elements of a.
The second line of the input contains n integers a1,a2,…,an (0≤ai≤106), where ai is the i-th element of a.
输入的第一行包含一个整数 n(1≤n≤2000)—— 表示数组 a 的元素个数。
输入的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤106),其中 ai 是数组 a 的第 i 个元素。
输出格式
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
输出一个整数——游戏结束后,未被删除的数组元素之和的最小可能值。
输入输出样例
输入#1
5 1 5 7 8 2
输出#1
0
输入#2
6 5 1 2 4 6 3
输出#2
0
输入#3
2 1000000 1000000
输出#3
1000000
输入解题思路,AI测评打分。不知道怎么写?