0

An array a of n integers between 0 and n-1 is given. The answer is a permutation of (0,...,n-1) such that:

a_0 + h_0 <= a_1 + h_1 <= ... <= a_n-1 + h_n-1 <= n-1

n <= 60 and the answer is unique.

For example if a is (0,2,4,2,0) the answer (h) is uniquely determined(as the problem promised):

h = (3,1,0,2,4)

a-z
  • 1,634
  • 4
  • 16
  • 35
  • 1
    This can't hold if for example `a = (1,1,1,...,1)` since we must have `a_i + h_i > = 1 + (n - 1) > n - 1` for some value `i`. Could you restate the question with stricter conditions on `a` and indicate what you mean when you say "The answer is"? – bossylobster May 01 '12 at 14:33
  • is `h` the resulting permutation? – amit May 01 '12 at 14:34
  • @bossylobster the unique answer is a part of problem statement, you should solve it assuming that, maybe `a` is too specific. – a-z May 01 '12 at 14:37
  • @amit yes, h is the permutation of (0,...,n-1). – a-z May 01 '12 at 14:38
  • @a-z just because the answer is unique does not mean that each entry of `a` is unique. Since you were able to use the term permutation correctly in the second sentence, you would have been better off saying `a` was a permutation. As for "the answer", you refer to `h` but never explicitly say `h` is the answer. – bossylobster May 01 '12 at 14:45

0 Answers0