codeforces-scrape

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

1312B.md (1267B)


      1 Source: https://codeforces.com/problemset/problem/1312/B
      2 
      3 B. Bogosort
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 You are given an array $a_1, a_2, \dots , a_n$. Array is good if for each pair of indexes $i \lt j$ the condition $j - a_j \ne i - a_i$ holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
     22 
     23 For example, if $a = [1, 1, 3, 5]$, then shuffled arrays $[1, 3, 5, 1]$, $[3, 5, 1, 1]$ and $[5, 3, 1, 1]$ are good, but shuffled arrays $[3, 1, 5, 1]$, $[1, 1, 3, 5]$ and $[1, 1, 5, 3]$ aren't.
     24 
     25 It's guaranteed that it's always possible to shuffle an array to meet this condition.
     26 
     27 Input
     28 
     29 The first line contains one integer $t$ ($1 \le t \le 100$) — the number of test cases.
     30 
     31 The first line of each test case contains one integer $n$ ($1 \le n \le 100$) — the length of array $a$.
     32 
     33 The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 100$).
     34 
     35 Output
     36 
     37 For each test case print the shuffled version of the array $a$ which is good.
     38 
     39 Example
     40 
     41 Input
     42 
     43 ```
     44 3
     45 1
     46 7
     47 4
     48 1 1 3 5
     49 6
     50 3 2 1 5 6 4
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 7
     57 1 5 1 3
     58 2 4 6 1 3 5
     59 ```