AmazonOA #271
Maximize Sum of Array Multiplication
估计简单可在线判题
Return a permutation p of the original indices 1..n that maximizes Σ(i×data[p[i]]), where i runs from 1 to n. If several permutations give the same maximum sum, return the lexicographically smallest index permutation. You return the sequence of original indices, not the sum or the new position of each original element.
输入格式
The first line contains n and the second line contains data. On this site 1≤n≤200000 and −10^9≤data[i]≤10^9.
输出格式
Output n one-based original indices in the order of the optimal permutation, separated by spaces.
样例 1
输入:
5
3 6 1 4 2
输出:
3 5 1 4 2
样例 2
输入:
4
2 1 2 1
输出:
2 4 1 3
样例 3
输入:
3
-1 -2 -3
输出:
3 2 1
样例说明
The answers are 3 5 1 4 2, 2 4 1 3 and 3 2 1 respectively. Equal values appear with the smaller original index first.