description stringlengths 35 9.39k | solution stringlengths 7 465k |
|---|---|
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | t=int(input())
for i in range(t):
n=int(input())
b=[0]*(2*n)
a=list(map(int,input().split()))
if 1 not in a:
print(-1)
else:
f=0
s=set()
for i in range(n):
if a[i]>=2*n:
f=1
break
else:
b[2*i]=a[i]
s.add(a[i])
fl=[]
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class A {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int TC = sc.nextInt();
while (TC --> 0) {
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.Scanner;
public class C1315 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int ntc = sc.nextInt();
while(ntc-->0){
int n = sc.nextInt();
int[] arr = new int[n];
int twiceN = 2*n +1;
int[] arrTw... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.util.*;
import java.math.*;
public class C {
public void realMain() throws Exception {
BufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);
String in = fin.readLine();
String[] ar = in.split(" ");
int T = Integer.parseInt(ar[0]);
for(int t = 0... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n = int(input())
lst = list(map(int,input().split()))
lst2 = []
for i in range(1,2*n+1):
lst2.append(i)
if max(lst) < len(lst):
print(-1)
else:
for i in lst:
lst2.remove(i)
lst3 = []
lst4 = [False] * n
for ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
bool present[1000] = {0};
int main(int argc, char **argv) {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 1; i <= 2 * n; i++) present[i] = false;
for (int i = 0; i < n; i++) ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | """
Author - Satwik Tiwari .
27th Oct , 2020 - Tuesday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import Byt... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import sys
from collections import Counter
def solve(N, B):
counts = Counter(B)
if any(v > 1 for v in counts.values()):
return -1
# Want smallest permutation that is element-wise greater than B
C = []
for x in range(1, 2 * N + 1):
if x not in counts:
C.append(x)
# ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
tree = list(range(2*n+10))
def find(st):
if tree[st]!=st:
tree[st] = find(tree[st])
return tree[st]
for c in arr:
tree[find(c)] = find(c+1)
ans = [0]*(2*n)
for i in rang... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | from collections import Counter
from collections import defaultdict
import math
t=int(input())
for _ in range(0,t):
n=int(input())
a=list(map(int,input().split()))
l=list()
k=1
d=defaultdict(lambda:0)
for i in range(0,n):
d[a[i]]=1
for i in range(0,n):
f=0
for j in ra... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, a, b, c, m, l, r, s;
void dihan() {
cin >> n;
vector<long long> x(n);
for (auto &i : x) cin >> i;
vector<long long> y(2 * n + 1);
for (i = 0; i < n; i++) y[x[i]] = i + 1;
priority_queue<long long> q;
vector<pair<long long, long long> >... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | def find(st, num):
mn = -1
for i in st:
if mn == -1:
if i > num:
mn = i
else:
if num < i < mn:
mn = i
return mn
def main():
n = int(input())
st = set()
for i in range(1, (n * 2) + 1):
st.add(i)
lst = list(map(i... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUF... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
const int N = int(2e5 + 20);
const int INF = int(1e9 + 5);
const long long LINF = int(1e18 + 20);
int main() {
int t;
cin >> t;
for (; t; t--) {
int n;
cin >> n;
set<int> ok;
for (int i = 1; i <= 2 * n; i++) ok.insert(i);
vector<int> a(n);
for ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.math.*;
import java.util.*;
public class Solve {
FastScanner in;
PrintWriter out;
void solve() {
int T = in.nextInt();
while (0 < T--) {
int n = in.nextInt();
int[] b = in.nextIntArray(n);
HashSet<Integer> hs = new HashSet<>... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.util.*;
public class C1315
{
public static void main(String args[])throws IOException
{
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;
public class Main
{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while (t-->0){
int n=Integ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class C623 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner obj=new Scanner(System.in);
int t=obj.nextInt();
while(t-->0)
{
int n=obj.nextInt();
Set<Intege... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.*;
import java.io.*;
import java.math.*;
public class C623{
public static int lower(ArrayList<Integer> a,int x){
int low=0;
int high=a.size();
while(low<high){
int mid=(low+high)/2;
if(x<=a.get(mid))
high=mid;
else
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10**9 + 7
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5)... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | t = int(input())
for _ in range(t):
n = int(input())
b = list(map(int, input().split()))
c = set(b)
l = []
valid = True
for i in b:
temp = i + 1
while temp in c:
temp += 1
if temp > 2*n:
print(-1)
valid = False
break
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | T = int(input().strip())
debug = False
for t in range(T):
N = int(input().strip())
A = list(map(int, input().split()))
totalSum = 2*N*(2*N+1)/2
total=0
d={}
for a in A:
d[a]=1
B = []
for a in A:
B.append(a)
total+=a
x=a
while True:... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Problem623C {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
int a[101], ac[202];
void solve() {
int n;
cin >> n;
bool f = 0;
memset(ac, 0, sizeof(ac));
for (int i = 0; i < n; i++) {
cin >> a[i];
ac[a[i]] = 1;
}
if (ac[1] == 0) {
f = 1;
}
vector<int> v;
for (int i = 0; i < n; i++) {
bool k = 0;
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n=int(input())
u=False
s=[]
k=[]
l=list(map(int,input().split()))
for i in range(1,2*n+1):
if i not in l:
k.append(i)
#print(k)
for i in range(n):
s.append(l[i])
for j in range(len(k)):
#print(k[j],l[i])
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
const double PI = atan(1.0) * 4;
const int64_t INF = 100000000000000003;
const int32_t LOG = 21;
const int MOD = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int tests = 1;
cin >> tests;
for (int ii = 0; ii < tests; ii++... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for tin in range(int(input())):
n=int(input())
b=list(map(int,input().split()))
c=[0]*(2*n+1)
for _ in range(len(b)):
c[b[_]]=1
a=[0]*(2*n)
v=0
for _ in range(n):
a[v]=b[_]
x=0
for j in range(b[_],2*n+1):
if c[j]!=1:
a[v+1]=j
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
int i, j, n, k, t, a[240], b[105], p[240];
int main() {
cin >> t;
for (k = 1; k <= t; k++) {
cin >> n;
for (i = 0; i++ < n;) {
cin >> b[i];
p[b[i]] = 1;
}
for (i = 0; i++ < n;) {
for (j = b[i]; p[j] && j <= 2 * n;) j++;
if (j > 2 ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
long double pi = 3.14159265358979;
using namespace std;
int inf = 1e9;
void fastIO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void solve() {
int n;
cin >> n;
vector<int> a(2 * n);
vector<bool> cur(2 * n, true);
for (int i = 0; i < 2 * n; i += 2) {
cin >... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | from collections import defaultdict
t = int(input())
for _ in range(t):
n = int(input())
b = list(map(int, input().split()))
b = list(map(lambda x: x-1, b))
flag = [False]*(2*n)
for bi in b:
flag[bi] = True
pair = defaultdict(int)
f = True
for bi in b:
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | if __name__ == '__main__':
t = int(input())
for _ in range(t):
n = int(input())
l = [int(i) for i in input().split(' ')]
res = []
a = sorted(list(set([i for i in range(1, 2 * n + 1)]) - set(l)))
# print(l)
# print(a)
for i in range(n):
cur = l... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
int t, a[109], n, vis[300];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> t;
while (t--) {
cin >> n;
memset(vis, 0, sizeof vis);
int good = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
vis[a[i]]++;
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def arr():return [int(i) f... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | t = int(input())
while t > 0:
n = int(input())
b = [int(x) for x in input().split()]
a = [0] * (2 * n + 1)
for i in b:
a[i] = 1
s = [0] * (2 * n + 1)
counter = 1
failed = False
for i in b:
s[counter] = i
found = False
for j in range(i + 1, 2 * n + 1):
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | t=int(input())
for l in range(t):
n=int(input())
tab=[0 for i in range(2*n)]
s=input().split()
for k in s:
tab[int(k)-1]=1
num=[]
for i in s:
j=int(i)-1
num.append(j+1)
for k in range(j,2*n):
if tab[k]==0:
tab[k]=1
num.a... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.*;
public class RestoringPermutation{
public static int find(Set<Integer> unusedNums, int a)
{
int min = 300;
for(int i : unusedNums)
{
if(i > a && i < min)
min = i;
}
return min;
}
public static void main(String []ar... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n=int(input())
b=list(map(int,input().split()))
done = [0]*(2*n+1)
if min(b)!=1 or max(b)==2*n:
print(-1)
else:
ans = [0]*(2*n+1)
for i in range(len(b)):
done[b[i]]=1
ans[2*i+1] = b[i]
# print(ans)
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.*;
public class EXPCH {
static long modInverse(long a, long m)
{
long m0 = m;
long y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1)
{
long q = a / m;
long t = m;
m = a % m;
a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x +... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
void solve() {
long long int n;
cin >> n;
vector<long long int> b(n);
map<long long int, long long int> mp;
set<long long int> st;
for (long long int i = 0; i < n; i++) {
cin >> b[i];
mp[b[i]]++;
}
for (long long int i = 1; i <... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.util.*;
public class QB_Jan
{
static class Print
{
private final BufferedWriter bw;
public Print()
{
this.bw=new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object)throws IOException
{
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import sys
from bisect import bisect_left
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def find_ge(a, x):
'Find leftmost item greater than or equal to x'
i = bisect_left(a, x)
if i != len(a):
return a[i]
return False
def gift():
for _ in range(cou):
n = int(in... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.*;
import java.io.*;
import java.util.Map.*;
public class C_1315 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
big:
while(t-->0) {
int n = sc.nextInt();
int[] arra... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | from sys import stdin, gettrace
if not gettrace():
def input():
return next(stdin)[:-1]
def main():
def solve():
n = int(input())
bb = [int(a) for a in input().split()]
avail = [False] + [True] * 2 * n
for b in bb:
avail[b] = False
res = []
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.*;
import java.io.*;
//odd selsection 1363-A
public class CodeForce {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] b = new int[n];
for (i... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
y = [*map(int, input().split())]
x = {*range(1, 2*n+1)}.difference(y)
res = []
for i in y:
a = [j for j in x if i < j]
if a:
b = min(a)
x.remove(b)
res.extend([i, ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.util.Arrays;
public class project
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> b(n);
vector<int> q;
unordered_set<int> s;
for (int i = 0; i < n; i++) {
cin >> b[i];
s.insert(b[i]);
}
for (int i = 1; i <= 2 * n; i++) {
if (s.... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
double getTime() { return clock() / (double)CLOCKS_PER_SEC; }
void read(){};
template <typename T, typename... Args>
void read(T& a, Args&... args) {
cin >> a;
read(args...);
}
void print(){};
template <typename T, typename... Args>
void print(T a, Args... args) {
cou... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
void solve() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
int maxi = 2 * n;
unordered_map<int, int> map;
for (long long i = 0; i < n; i++) {
cin >> a[i];
map[a[i]]++;
}
if (map.count(1) <= 0) {
cout << -... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | t=int(input())
for kk in range(t):
n=int(input())
l=list(map(int,input().split()))
l1=list(filter(lambda x:x not in l,range(1,n*2+1)))
l2=[]
for i in l:
j=0
flag=0
while j<len(l1):
if l1[j]>i:
l2.append(l1[j])
flag=1
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | # import sys
# sys.stdin = open("test.txt", 'r')
for _ in range(int(input())):
n = int(input())
b = list(map(int, input().split()))
p = list(range(1, 2*n+1))
inb = set(b)
a = {}
for i, v in enumerate(b):
if v == 2*n:
print(-1)
break
c = [z for z in p[p.in... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> b(n + 5);
vector<int> a(2 * n + 10);
vector<pair<int, int>> p;
map<int, int> mp;
for (int i = 1; i ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import copy
for i in range(int(input())):
n=int(input())
l=[int(j) for j in input().split()][:n]
l1=list(set(list(range(1,2*n+1))).difference(set(l)))
t=copy.deepcopy(l)
l1.sort()
m=-1
for k in range(n):
h=-1
for j in range(n):
if(l1[j]>t[k]):
if l... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
const int N = 205;
int b[N], p[N], a[N];
int n;
void check() {
for (int i = 0; i < 2 * n; i += 2) {
a[i] = b[i / 2];
bool flag = false;
for (int j = b[i / 2] + 1; j <= 2 * n; ++j) {
if (p[j] == 0) {
p[j] = 1, a[i + 1] = j;
flag = true;
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import bisect
t = int(input())
for i in range(t):
n = int(input())
l = list(map(int,input().split()))
l1 = []
l2 = []
c = 0
l3 = sorted(l)
for i in range(min(l)+1,2*n+1):
if i not in l:
l1.append(i)
if len(l1) == 0:
print(-1)
else:
for i in l:
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | from sys import stdin
from collections import deque
mod = 10**9 + 7
import sys
import random
# sys.setrecursionlimit(10**6)
from queue import PriorityQueue
# def rl():
# return [int(w) for w in stdin.readline().split()]
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdi... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for ttt in range(int(input())):
n=int(input())
arr=list(map(int,input().split()))
if 2*n in arr or 1 not in arr:
print(-1)
continue
res=[]
for i in range(n):
res.append(arr[i])
for j in range(arr[i]+1,2*n+1):
if (j not in arr) and (j not in res):
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long int a[n];
map<long long int, long long int> m;
for (int i = 0; i < n; i++) {
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | ##############--->>>>> Deepcoder Amit Kumar Bhuyan <<<<<---##############
"""
Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | # from collections import deque
import sys
input = lambda: sys.stdin.readline().strip()
for i in range(int(input())):
n = int(input())
b = list(map(int,input().split()))
q = [i+1 for i in range(2*n)]
used = set(b)
j = 0
a = [0]*2*n
f = True
for i in range(n):
a[2*i]=b[i]
for ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | # ///////////////////////////////////////////////////////////////////////////
# //////////////////// LEGEND ////////////////////////
# ///////////////////////////////////////////////////////////////////////////
import sys,os,io
from sys import stdin
import math
from collections import defaultdict
from heapq import hea... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader bf = new BufferedReader(new ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
int mark[2005];
int main() {
long long n, m, i, j, t, x, y, w, k, a, b;
cin >> t;
while (t--) {
cin >> n;
vector<pair<int, int> > v;
memset(mark, 0, sizeof mark);
for (i = 0; i < n; i++) {
cin >> x;
v.push_back({x, -1});
mark[x] = 1;
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n=int(input())
b=[int(x) for x in input().split()]
a=[]
for i in range(n):
a.append(b[i])
k=b[i]
while k in a or k in b:k+=1
if k>2*n:print(-1);break
a.append(k)
else:print(*a) |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | I=input
for _ in[0]*int(I()):
I();b=*map(int,I().split()),;s={*range(2*len(b)+1)}-{*b};a=[]
try:
for x in b:a+=x,min(s-{*range(x)});s-={*a}
except:a=-1,
print(*a) |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
dic={};ans=[];boo=False
for i in a:
dic[i]=0
for i in a:
ans.append(i)
temp=i+1
while(True):
if(temp>2*n):
boo=True
break
if(temp not ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.util.*;
public class test {
static int m[];
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
int t=sc.nextInt();
while (t-->0){
StringBuilder sb=new StringBuilder();
int N=sc.nextInt();
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.*;
public class Sol{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int[] b=new int[n+1];
int[] bb=new int[n];
int le=2*n;
Set<Integer> h=new HashSet<>(); int min=0;
ArrayLi... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 20;
const int inf = 0x3f3f3f3f;
const int modd = 1e9 + 7;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') x =... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int a = sc.nextInt();
int[] x = new int[a + 1];
int min = 1;
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int test = scanner.nextInt();
for(int t = 0; t<test; ++t){
int... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.Scanner;
import java.util.Stack;
import java.util.Arrays;
public class C{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int t = in.nextInt();
StringBuilder res = new StringBuilder();
o1: for(int j = 0;j<t;++j){
StringBuilder resLocal = new StringBuilder(... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.util.*;
public class Main
{
static BufferedReader br;
static StringTokenizer st;
static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static class HS<T> extends HashSet<T> {};
public static void main(String[] ar... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, t, c;
cin >> t;
for (; t > 0; t--) {
c = 1;
cin >> n;
int a[2 * n];
bool x[2 * n + 1];
memset(x, 0, sizeof(x));
j = 1;
for (i = 0; i < n; i++) {
cin >> k;
a[2 * i] = k;
x[k] = 1;
}
for ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | from collections import Counter as C,defaultdict as D,deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL,bisect_right as BR
from heapq import heappush as HPUSH,heappop as HPOP
from math import floor as MF,ceil as MC, gcd as MG,factorial as F,sqrt as S... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.Scanner;
public class RestoringPermutation {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-->0){
int n = sc.nextInt();
int arr[] = new int[n];
int covered[] =... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... |
for i in range(int(input())):
n = int(input())
b_array = list(map(int, input().split()))
a_array = sorted(list(set(list(map(int, range(1, 2*n+1)))) - set(b_array)))
sorted_array = sorted(list(map(list, list(zip(b_array, list(map(int, range(n))))))))
#print(sorted_array)
final_array = [0]*(2*n)
state = True
for... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n = int(input())
seq = list(map(int, input().split()))
if(len(set(seq))) != n or max(seq) > 2 * n - 1:
print(-1)
continue
myst = set(range(1, 2 * n + 1)) - set(seq)
myst = list(sorted(myst))
#fnd = list(sorted(map(lambda tp: (tp[1], tp[0]), enumerate... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int n;
int in;
bool ispossible;
bool ischanged;
while (t--) {
ispossible = true;
map<int, bool> isused;
vector<int> a;
vector<int> b;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> in;
a.push_ba... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n=int(input())
L=[int(x) for x in input().strip().split(" ")]
exist=set(L)
todo=set()
for i in range(1,2*n+1):
if i not in exist:
todo.add(i)
res=[]
flag=True
for x in L:
for e in range(x+1,2*n+1):
if e in todo:
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const long long int ths = 1LL << 40;
const int NN = 5e3 + 6;
void solve() {
long long int n;
cin >> n;
long long int b[n... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #Ashish Sagar
import math
q=int(input())
#q=1
for _ in range(q):
n=int(input())
b=list(map(int,input().split()))
ans=[0]*(2*n)
if min(b)!=1 or max(b)==2*n:
print(-1)
else:
l=[1]*(2*n+1)
for i in range(n):
l[b[i]]=0
#print(l)
'''aa=[]
fo... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Random;
import java.io.PrintWriter;
/*
Solution Created: 19:12:1... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.*;import java.io.*;import java.math.*;
public class Main
{
public static void process()throws IOException
{
int n=ni();
TreeSet<Integer> set = new TreeSet<Integer>();
for(int i=1;i<=2*n;i++)
set.add(i);
int[]B=nai(n);
for(int i=0;i<n;i++)
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.*;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
int tests = s.nextInt();
while(tests--!=0){
int n = s.nextInt();
int f... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | //package Practise;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class RestoringPermutation {
public ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | test=int(input())
for i in range(test):
n = int(input())
b = list(map(int, input().split()))
a = [0 for i in range(n+n)]
l = [0 for i in range(n+n+1)]
for i in range(n):
a[2*i] = b[i]
l[b[i]] = 1
ans = 1
for i in range(n):
bool = 0
for j in range(b[i]+1, n+n+1):
if l[j] == 1:
continue
a[2*i+1] ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
void solve() {
int64_t n;
cin >> n;
int64_t b[n + 1], a[2 * n + 1];
map<int64_t, int64_t> f;
while (1 > 2)
;
while (1 > 2)
;
while (1 > 2)
;
bool fl = 0;
for (int64_t i = 1; i <= n; ++i) {
cin >> b[i];
while (1 > 2)
;
while (1... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import sys
from collections import defaultdict
def make(b):
n=len(b)
ans=[-1 for _ in range(2*n)]
vis=defaultdict(int)
for i in range(0,2*n,2):
ans[i]=b[i//2]
vis[b[i//2]]=1
for i in range(1,2*n,2):
for j in range(ans[i-1]+1,2*n+1):
if vis[j]==0:
a... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.*;
import java.util.*;
public class RestoringPermutation{
static Scanner sc = new Scanner(System.in);
static void restorePermutation(){
int n = sc.nextInt();
boolean map[] = new boolean[(2*n + 1)];
int input[] = new int[n];
int output[] = new int[n];
map[0] ... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;
import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;
import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Array;import java.lang.reflect.Field;impo... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
map<int, int> m;
bool f = true;
vector<int> v;
while (n--) {
int a;
cin >> a;
v.push_back(a);
m[a] += 1;
if (m[a... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import heapq
def restorePermutation(n, A):
ans = []
unUsed = set(list(range(1, 2*n + 1)))
for val in A:
if not 1 <= val <= 2*n: return -1
ans.append(val)
ans.append(-1)
unUsed.remove(val)
minHeapq = [val for val in unUsed]
heapq.heapify(minHeapq)
#idea us... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for _ in range(int(input())):
n=int(input())
br=list(map(int,input().split()))
ar=[0]*2*n
for i in range(0,2*n,2):
ar[i]=br[i//2]
se=set(br)
for i in range(0,2*n,2):
for k in range(ar[i]+1,3*n):
if(not(k in se)):
ar[i+1]=k
se.add(k)
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class RestoringPermutation {
public static void main(String[] args) {
FastReader input=new FastReader();
int t... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import sys
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
tests = inp()
testcount = 0
while testcount < tests:
n = inp()
b = inl... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
int[] a = new int[n];
int[] b = new int[2*n+1];
for(int i=0;i<n;i++)
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | for t in range(int(input())):
n = int(input())
b = list(map(int, input().split()))
used = [False]*(n*2)
a = []
for x in b:
used[x-1] = True
for x in b:
for i in range(x+1, 2*n+1):
if not used[i-1]:
a.append(x)
a.append(i)
... |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | I=input
for _ in[0]*int(I()):
n=2*int(I());a=[0]*n;b=a[::2]=*map(int,I().split()),;c={*range(n+1)}-{*b};i=1
try:
for x in b:y=a[i]=min(c&{*range(x,n+1)});c-={y};i+=2
except:a=-1,
print(*a) |
You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... |
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.