codeforces-scrape

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

686B.md (2332B)


      1 Source: https://codeforces.com/problemset/problem/686/B
      2 
      3 B. Little Robber Girl's Zoo
      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 Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.
     22 
     23 The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers *l* and *r* such that *r* - *l* + 1 is even. After that animals that occupy positions between *l* and *r* inclusively are rearranged as follows: the animal at position *l* swaps places with the animal at position *l* + 1, the animal *l* + 2 swaps with the animal *l* + 3, ..., finally, the animal at position *r* - 1 swaps with the animal *r*.
     24 
     25 Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
     26 
     27 Input
     28 
     29 The first line contains a single integer *n* (1 ≤ *n* ≤ 100) — number of animals in the robber girl's zoo.
     30 
     31 The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 109), where *a**i* is the height of the animal occupying the *i*-th place.
     32 
     33 Output
     34 
     35 Print the sequence of operations that will rearrange the animals by non-decreasing height.
     36 
     37 The output should contain several lines, *i*-th of the lines should contain two space-separated integers *l**i* and *r**i* (1 ≤ *l**i* < *r**i* ≤ *n*) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed.
     38 
     39 The number of operations should not exceed 20 000.
     40 
     41 If the animals are arranged correctly from the start, you are allowed to output nothing.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4  
     49 2 1 4 3
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 1 4
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 7  
     62 36 28 57 39 66 69 68
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 1 4  
     69 6 7
     70 ```
     71 
     72 Input
     73 
     74 ```
     75 5  
     76 1 2 1 2 1
     77 ```
     78 
     79 Output
     80 
     81 ```
     82 2 5  
     83 3 4  
     84 1 4  
     85 1 4
     86 ```
     87 
     88 Note
     89 
     90 Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.