0% found this document useful (0 votes)
80 views2 pages

Problem - 1691B - Codeforces

Uploaded by

RITESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views2 pages

Problem - 1691B - Codeforces

Uploaded by

RITESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4/1/24, 8:56 AM Problem - 1691B - Codeforces

|
riteshnub | Logout
You have +385! Wow!

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST

00:05:45

CodeCraft-22 and Codeforces


Round 795 (Div. 2)
B. Shoe Shuffling Finished
time limit per test: 1 second
Practice
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

A permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For


example, [2, 3, 1, 5, 4] is a permutation, but [1, 2, 2] is not a permutation (2 appears twice in → Clone Contest to Mashup 
the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array).
You can clone this contest to a mashup.
Input
Each test contains multiple test cases. The first line contains a single integer t ( Clone Contest
1 ≤ t ≤ 1000) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer n (1 ≤ n ≤ 10


5
) — the number of → Submit?
students.
Language: GNU G++17 7.3.0
The second line of each test case contains n integers s1 , s2 , … , sn (1 ≤ si ≤ 10
9
, and for
all 1 ≤ i < n , si ≤ si+1 ) — the shoe sizes of the students. Choose
Choose File No file chosen
file:
5
It is guaranteed that the sum of n over all test cases does not exceed 10 . Submit

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.

Example → Contest materials


input Copy
Announcement (en)
2
5 Tutorial (en)
1 1 1 1 1
6
3 6 8 13 15 21

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.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Apr/01/2024 08:56:38UTC+5.5 (h2).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

https://codeforces.com/problemset/problem/1691/B 2/2

You might also like