【例57.2】 上一个排列
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Description
Everyone on Earth knows that from to (), these numbers can form different permutations. Now, if we sort these permutations in lexicographical order from smallest to largest, given one permutation, find its previous permutation.
Input Format
The first line contains an integer , representing the length of the permutation.
The second line contains integers separated by spaces, representing a permutation of the numbers from to .
Output Format
If the previous permutation exists, output it; otherwise, output "ERROR".
Sample
4
2 1 3 41 4 3 2
20251025D班作业(4)
- Status
- Done
- Problem
- 12
- Open Since
- 2025-10-26 0:00
- Deadline
- 2025-11-3 23:59
- Extension
- 24 hour(s)