Problem - 1691B - Codeforces
Problem - 1691B - Codeforces
|
riteshnub | Logout
You have +385! Wow!
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP
00:05:45
A class of students got bored wearing the same pair of shoes every day, so they decided to → Virtual participation
shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is
Virtual contest is a way to take part in past
considered as a single object. contest, as close as possible to participation
on time. It is supported only ICPC mode for
There are n students in the class, and you are given an array s in non-decreasing order, virtual contests. If you've seen these
problems, a virtual contest is not for you -
where si is the shoe size of the i -th student. A shuffling of shoes is valid only if no student solve these problems in the archive. If you
gets their own shoes and if every student gets shoes of size greater than or equal to their just want to solve some problem from a
contest, a virtual contest is not for you -
size. solve this problem in the archive. Never use
someone else's code, read the tutorials or
You have to output a permutation p of {1, 2, … , n} denoting a valid shuffling of shoes, communicate with other person during a
virtual contest.
where the i -th student gets the shoes of the pi -th student (pi ≠ i). And output −1 if a valid
shuffling does not exist. Start virtual contest
Output
For each test case, print the answer in a single line using the following format.
→ Problem tags
If a valid shuffling does not exist, print the number −1 as the answer.
constructive algorithms greedy
If a valid shuffling exists, print n space-separated integers — a permutation p of 1, 2, … , n implementation two pointers *1000
denoting a valid shuffling of shoes where the i -th student gets the shoes of the pi -th student. No tag edit access
If there are multiple answers, then print any of them.
output Copy
5 1 2 3 4
-1
Note
In the first test case, any permutation p of 1, … , n where pi ≠ i would represent a valid
shuffling since all students have equal shoe sizes, and thus anyone can wear anyone's shoes.
https://codeforces.com/problemset/problem/1691/B 1/2
4/1/24, 8:56 AM Problem - 1691B - Codeforces
In the second test case, it can be shown that no valid shuffling is possible.
Supported by
https://codeforces.com/problemset/problem/1691/B 2/2