Waterloo 2017 Winter C - Vera and Mean Sorting

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
2017 Winter Waterloo Local ACM Contest, Problem C

The harmonic mean of a sequence of positive integers x1,,xN is

H(x1,,xN)=(i=1Nxi1N)1

Vera classifies an array of positive integers A=[A1,,AN] of length N as K-mean-sorted if M(i)M(i+1) for 1iNK where

M(i)=H(Ai,,Ai+K1)

A permutation P is an ordered set of integers P1,P2,,PN, consisting of N distinct positive integers, each of which are at most N.

Permutation P is lexicographically smaller than permutation Q if there is i (1in), such that Pi<Qi, and for any j (1j<i) Pj=Qj.

Given integers N and K, help Vera find the lexicographically smallest permutation P of integers 1 to N such that P is K-mean-sorted but not L-mean-sorted for 1LN1, LK.

If no such permutation exists, output 0.

Constraints

  • 2N100
  • 1KN1
  • N,K are integers

Input Specification

The input will be in the format:

N K

Output Specification

Output one line with the desired permutation. If such permutation does not exist, output one line with 0.

Sample Input 1

Copy
3 2

Sample Output 1

Copy
2 3 1

Sample Input 2

Copy
4 1

Sample Output 2

Copy
0

Comments

There are no comments at the moment.