codeforces-scrape

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

482A.md (1072B)


      1 Source: https://codeforces.com/problemset/problem/482/A
      2 
      3 A. Diverse Permutation
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Permutation *p* is an ordered set of integers *p*1,   *p*2,   ...,   *p**n*, consisting of *n* distinct positive integers not larger than *n*. We'll denote as *n* the length of permutation *p*1,   *p*2,   ...,   *p**n*.
     22 
     23 Your task is to find such permutation *p* of length *n*, that the group of numbers |*p*1 - *p*2|, |*p*2 - *p*3|, ..., |*p**n* - 1 - *p**n*| has exactly *k* distinct elements.
     24 
     25 Input
     26 
     27 The single line of the input contains two space-separated positive integers *n*, *k* (1 ≤ *k* < *n* ≤ 105).
     28 
     29 Output
     30 
     31 Print *n* integers forming the permutation. If there are multiple answers, print any of them.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 3 2
     39 ```
     40 
     41 Output
     42 
     43 ```
     44 1 3 2
     45 ```
     46 
     47 Input
     48 
     49 ```
     50 3 1
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 1 2 3
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 5 2
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 1 3 2 4 5
     69 ```
     70 
     71 Note
     72 
     73 By |*x*| we denote the absolute value of number *x*.