CF1180B.Nick and Array
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Nick had received an awesome array of integers a=[a1,a2,…,an] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a1⋅a2⋅…an of its elements seemed to him not large enough.
He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index i (1≤i≤n) and do ai:=−ai−1.
For example, he can change array [3,−1,−4,1] to an array [−4,−1,3,1] after applying this operation to elements with indices i=1 and i=3.
Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index.
Help Kolya and print the array with the maximal possible product of elements a1⋅a2⋅…an which can be received using only this operation in some order.
If there are multiple answers, print any of them.
尼克在他5岁生日时收到了母亲送给他的一份超棒的整数数组 a=[a1,a2,…,an] 作为礼物。他本打算深入探究该数组的各种性质,但拆开包装后却大失所望——因为其所有元素的乘积 a1⋅a2⋅…an 在他看来并不够大。
他正准备把整个数组扔掉,但母亲安慰了他。她告诉他,对该数组执行如下操作后,数组并不会“变质”:任选一个下标 i(满足 1≤i≤n),并将 ai 替换为 −ai−1。
例如,对数组 [3,−1,−4,1] 分别在下标 i=1 和 i=3 处执行该操作后,可得到新数组 [−4,−1,3,1]。
科里亚立刻意识到,有时通过该操作能显著增大数组中整数的乘积。现在他决定:仅使用这一操作(可对任意元素执行零次、一次或多次,且允许对同一位置重复执行),来获得元素乘积 a1⋅a2⋅…an 尽可能大的数组。
请帮助科里亚,输出一个可通过若干次(按任意顺序)执行该操作而得到的、具有最大可能乘积的数组。
若存在多个满足条件的答案,输出任意一个即可。
输入格式
The first line contains integer n (1≤n≤105) — number of integers in the array.
The second line contains n integers a1,a2,…,an (−106≤ai≤106) — elements of the array
第一行包含一个整数 n(1≤n≤105)—— 表示数组中整数的个数。
第二行包含 n 个整数 a1,a2,…,an(−106≤ai≤106)—— 表示数组的元素。
输出格式
Print n numbers — elements of the array with the maximal possible product of elements which can be received using only this operation in some order from the given array.
If there are multiple answers, print any of them.
输出 n 个数——即从给定数组出发,仅通过该操作以某种顺序执行后所能得到的、元素乘积最大的数组中的各元素。
若存在多个答案,输出其中任意一个即可。
输入输出样例
输入#1
4 2 2 2 2
输出#1
-3 -3 -3 -3
输入#2
1 0
输出#2
0
输入#3
3 -3 -3 2
输出#3
-3 -3 2
输入解题思路,AI测评打分。不知道怎么写?