AmazonOA #28
Find Optimal Permutation
Estimated EasyJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
Output a permutation p of 1..n that maximizes Σ i×data[p[i]−1], where i starts from 1. If the maximum is tied, choose the lexicographically smallest index permutation.
Input
The first line contains n (1..100000); the second line contains n positive integers (1..10⁹).
Output
Output n indices.
Example 1
Input:
3
2 1 2
Output:
2 1 3
Example 2
Input:
1
7
Output:
1
Example 3
Input:
3
3 3 1
Output:
3 1 2
Example notes
Example 1: the values in order are 1, 2, 2, and the two equal 2s are placed by original indices 1, 3, so the output is 2 1 3 with sum 11. Example 2: the only possible output is 1. Example 3: value 1 goes first, followed by indices 1, 2, so the output is 3 1 2.
Editorial
Loading solution…