codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1180B.md (2113B)


      1 Source: https://codeforces.com/problemset/problem/1180/B
      2 
      3 B. Nick and Array
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Nick had received an awesome array of integers $a=[a_1, a_2, \dots, a_n]$ 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 $a_1 \cdot a_2 \cdot \dots a_n$ of its elements seemed to him not large enough.
     22 
     23 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 \le i \le n$) and do $a_i := -a_i - 1$.
     24 
     25 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$.
     26 
     27 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.
     28 
     29 Help Kolya and print the array with the maximal possible product of elements $a_1 \cdot a_2 \cdot \dots a_n$ which can be received using only this operation in some order.
     30 
     31 If there are multiple answers, print any of them.
     32 
     33 Input
     34 
     35 The first line contains integer $n$ ($1 \leq n \leq 10^{5}$) — number of integers in the array.
     36 
     37 The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^{6} \leq a_i \leq 10^{6}$) — elements of the array
     38 
     39 Output
     40 
     41 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.
     42 
     43 If there are multiple answers, print any of them.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 4
     51 2 2 2 2
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 -3 -3 -3 -3
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 1
     64 0
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 0
     71 ```
     72 
     73 Input
     74 
     75 ```
     76 3
     77 -3 -3 2
     78 ```
     79 
     80 Output
     81 
     82 ```
     83 -3 -3 2
     84 ```