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... | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int done = 1;
for (int i = 0; i < t; i++) {
done = 1;
int n;
cin >> n;
int A[n];
int B[2 * n];
int check[2 * n];
for (int i = 0; i < 2 * n; i++) {
check[i] = 0;
}
for (int j = 0; j < n; 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... | import heapq
def solve(n,t):
remainingCandidates = sorted(list(set([a for a in range(1,2*n + 1)]) - set(t) - set([x for x in range(1, sorted(t)[0], 1)])))
if len(remainingCandidates) != n:
return -1
else:
used = [False]*len(remainingCandidates)
ans = []
for i,x in 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;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &V) {
os << "[ ";
for (auto v : V) os << v << " ";
return os << "]";
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &S) {
os << "{ ";
for (auto s : S) os << s << " ";
return ... |
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:y=min(s-{*range(x)});s-={y};a+=x,y
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... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> b(n);
vector<int> a(2 * n);
vector<char> used(2 * n);
for (int i = 0; i < n; ++i) {
cin >> b[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... | n = int(input())
for a in range(n):
answer = ""
size = int(input())
nums = list(map(int,input().split()))
taken = set(nums)
possible = True
if 1 not in taken:
print(-1)
continue
for num in nums:
answer += str(num) + " "
found = False
for b in range(num... |
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()))
a=[]
rem=set([i for i in range(1,2*n+1)])-set(b)
f=True
for i in range(n):
a.append(b[i])
ai=float('inf')
for j in rem:
if j>b[i] and ai>j:
ai=j
if ai==float(... |
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
import bisect
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().rstrip().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
finalans = []
t = ini()
for _ in range(t):
n = ini()
... |
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;
int a[n];
vector<bool> flag(2 * n + 1, false);
for (int i = 0; i < n; i++) {
cin >> a[i];
flag[a[i]] = true;
}
vector<int> st;
for (int i = 1; i <= 2 * 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... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
const int MOD = 1000000007;
int mod = 999998639;
inline long long qpow(long long b, long long e, long long m = MOD) {
long long a = 1;
for (; e; e >>= 1, b = b * b % m)
if (e & 1) a = a * b % m;
return a;
}
set<int> s;
int b[109];
vector<... |
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... | # -*- coding: utf-8 -*-
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] 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 sys
import bisect
def metod(x):
if t[x] == "A":
w = a
else:
w = b
for i in range(x + 1, len(t)-1):
if t[i] != t[i - 1]:
if t[i] == "A":
w+=a
else:
w+=b
return w
def morzermorzer():
n = int(input())
w = li... |
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 min_number_after(number:int):
global other_sequence
for k in range(len(other_sequence)):
if other_sequence[k] > number:
return other_sequence[k]
return "No"
def list_subtract():
global sequence, n
other_sequence = list(range(1, 2*n+1))
for k in sequence:
other_sequence.remove(k)
return other_sequenc... |
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
t=int(sys.stdin.readline())
for i in range(t):
n=int(sys.stdin.readline())
b=[int(j) for j in sys.stdin.readline().split()]
arr=[]
# perm=[]
# for p in range(1,2*n+1):
# perm.append(p+1)
tot=2*n
mark=[0]*tot
for g in range(n):
mark[b[g]-1]=1
ans=True
for h in range(n):
done=0
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 defaultdict, Counter
def getlist():
return list(map(int, input().split()))
def main():
t = int(input())
for num in range(t):
n = int(input())
arr = getlist()
arr1=arr.copy()
box = []
if min(arr)!=1 or max(arr)>=2*n:
print(-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, deque
inp = sys.stdin.readline
read = lambda: list(map(int, inp().split()))
def a():
ans = ""
for _ in range(read()[0]):
a, b, x, y = read()
x += 1
y += 1
ans += str(max(((a-x)*(b)), ((x-1)*(b)), ((a)*(b-y)), ((a)*(y-1)))) + "\n"
print(ans)
def c():
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.Arrays;
import java.util.HashSet;
import java.util.Scanner;
public class restoringPermutation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder finalAns = new StringBuilder();
int t = sc.nextInt();
while (--t >= 0) {
StringBuilder ans = new Strin... |
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;
template <typename T>
using second = set<T>;
template <typename T>
using v = vector<T>;
const int Max = 2e5 + 100;
const int Mx = 5e1 + 10;
const int Len = 1e6;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
int A[Max];
bool usedNum[Max];
int main() {
int q;
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... | import java.util.*;
import java.util.stream.Collectors;
public class RestoringPermutation {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int test = scanner.nextInt();
scanner.nextLine();
for (int t = 0; t < test; t++) {
int n = scan... |
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 long long inf = 1e16;
const long long N = 1e5 + 1;
const long long mod = 1e9 + 7;
void solve() {
long long n;
cin >> n;
long long b[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> b[i];
}
deque<long long> ans(2 * n + 1), rem;
for (long long 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... | import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
n = int(input())
b = list(map(int,input().split()))
a = [0]*(2*n)
d = {i:True for i in range(1,2*n+1)}
for i in range(n):
p = i+1
pos = 2*p-1
a[pos-1] = b[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 bisect import bisect_right
t = int(input())
for _ in range(t):
n = int(input())
b = [ int(x) for x in input().split()]
arr = [False]*(2*n+1)
result = [0]*(n*2)
for i, val in enumerate(b):
result[i*2] = val
arr[val] = True
arr[0] = True
arr = [ i for (i, v) in 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... | for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
h=[0]*((2*n)+1)
for i in l:
h[i]=1
sl=[]
i=0
mm=0
for i in range(n):
flag=0
for j in range(l[i]+1,(2*n)+1):
if h[j]==0:
flag=1
sl.append(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... |
# Author : raj1307 - Raj Singh
# Date : 23.02.2020
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
... |
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())
l = list(map(int , input().split(' ')))
s = set(l)
l2 = []
for j in range(1 , 2*n + 1):
if(j not in s):
l2.append(j)
l2.sort()
done = 0
for j in range(len(l2)):
flag = 0
for k in range(n):
if(isinstance(l[k] , int) and l2[j] > l[k]):
l[k] = [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... | def oki(n,lst):
tm = []
for i in range(1,2*n+1):
if i not in lst:
tm.append(i)
out = []
for i in lst:
temp = None
for j in range(i + 1, 2*n+1):
if j in tm:
temp = j
break
if temp == None:
out = []
... |
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())
def closest_greater(num,a):
for x in range(num,len(a)):
if(a[x] == 1):
a[x] = 0
return x
return -1
while(t>0):
n = int(input())
s = input()
b = ['0']
b= b+ s.split()
a = [1]*(2*len(b) - 1)
flag = 0
ans = []
for x in range(1,len(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... | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int b[n + 1];
set<int> s;
for (int i = 0; i < n; i++) {
cin >> b[i];
s.insert(b[i]);
}
int a[n * 2 + 5];
memset(a, 0, sizeof(a));
int pos = 0;
for (int 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 long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
const long long nax = 0;
void solve() {
long long n;
vector<long long> b(210, 0), arr(105);
vector<bool> vis(210, 0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> arr[i];
vis[arr[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... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
FastReader scan = new FastReader();
//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("taming.out")));
PrintWriter out = new PrintWriter(new BufferedWrit... |
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
for _ in range(int(input())):
nb = int(input())
b = [int(j) for j in input().split()]
vis = [0 for i in range(nb*2)]
for i in range(nb):
vis[b[i]-1]=1
l = []
for i in range(2*nb):
if not vis[i]:
l.append(i+1)
ans = []
for i in b:
ind = bi... |
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:
t-=1
n=int(input())
a=list(map(int,input().split()))
x=[]
for i in range(n):
x.append(a[i])
k=a[i]+1
q=True
while q==True:
if k in a or k in x :
k=k+1
else:
q=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... | import sys
# input = lambda: sys.stdin.readline().rstrip()
def last_proverka(v):
for i in range(len(v)):
i += 1
if i not in v:
return -1
return True
# v - ans
# h - b
def l_proverka(v, c):
for i in range(len(c)):
if v[i] == c[i]:
return False
retu... |
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;
//https://codeforces.com/problemset/problem/1315/C
public class ResortingPermutations {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
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... | from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
#sys.setrecursionlimit(100000)
for i in range(int(input())):
n=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;
const int INF = 0x3f3f3f3f;
int a[205], b[105];
set<int> st;
int n;
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> b[i];
st.clear();
for (int i = 1; i <= 2 * n; i++) st.insert(i);
for (int i = 1; i <= n; i++) {
st.erase(b[i]);
}
if (st.size()... |
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... | # -*- coding: utf-8 -*-
"""
Created on Tue Sep 22 20:42:16 2020
@author: Dark Soul
"""
t=int(input(''))
for _ in range(t):
n=int(input(''))
tst=list(map(int,input().split()))
b=[0]
for i in tst:
b.append(i)
a=[0]*(2*n+1)
used=[0]*(2*n+1)
khaise=0
for i in range(1,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... | import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;
public class P1315C {
public static void main(String[] args) {
SimpleScanner scanner = new SimpleScanner(System.in);
PrintWriter writer = new PrintWriter(System.out);
int caseNum = scanner.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... | #include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
for (pair<T1, T2> &t : v) is >> t.first >> t.second;
return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &t : v) is >> t;
return is... |
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.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int a[]=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... | def revolt(n,l):
l1=[0 for i in range(2*n)]
j=0
i=0
while j<n:
l1[i]=l[j]
j+=1
i+=2
d={}
for e in l:
d[e]=True
k=1
while k<2*n :
val=l1[k-1]+1
while d.get(val) and val<=2*n:
val+=1
if val>2*n:
return -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 bisect
import sys
import math
input=sys.stdin.readline
t=int(input())
#t=1
for _ in range(t):
n=int(input())
#a,b=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*(2*n)
j=0
ind=[0]*(2*n+1)
for i in range(n):
ind[l[i]]=1
for i in range(n):
a[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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> a(n), ans(2 * n), used(2 * n + 5);
for (int i = 0; i < n; i++) {
cin >> a[i];
used[a[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;
bool cmp(pair<long long int, long long int> a,
pair<long long int, long long int> b) {
return a.first < b.first;
}
bool check(int a) {
int sum = 0;
while (a > 0) {
sum += (a % 10);
a /= 10;
}
if (sum == 10) return true;
return false;
}
bool prim... |
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_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t, n, last;
cin >> t;
bool can;
for (int u = 0; u < t; ++u) {
cin >> n;
vector<int> a(2 * n + 1, 0);
vector<int> c(2 * n + 1, 0);
last = 1;
vector<pair<int, 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... | // Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class ll
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br ... |
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 mi():return map(int,input().split())
def li():return list(mi())
def ii():return int(input())
def si():return input()
t=ii()
while(t):
t-=1
n=ii()
a=li()
b=a[:]
b.sort()
a1=[]
l=0
for i in range(1,2*n+1):
if(l<len(b) and i==b[l]):
l+=1
else:
a1.... |
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=list(map(int,input().split()))
if 2*n in l:
print(-1)
else:
t=[]
x=[0]*(2*n+1)
f=0
for i in l:
x[i]=1
for i in l:
if 0 not in x[i:]:
f=1
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... | for _ in range(int(input())):
n = int(input())
b = list(map(int, input().split()))
a = [0 for i in range(2*n)]
for i in range(n):
a[2*i] = b[i]
rec = {}
# for i in range(n):
# rec[b[i]] = i
avail = [1 for i in range(1, 2*n + 1)]
for i in b:
avail[i - 1] = 0
g... |
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... | te = int(input())
while te > 0:
te -= 1
n = int(input())
B = list(map(int, input().split()))
D = {}
for i in B:
D[i] = 1
ans = []
i = 0
while i < n:
ans.append(B[i])
k = B[i]
while k < 2*n:
k += 1
if D.get(k) is None:
... |
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 long int full = 205;
int n;
int b[full], a[full];
bool f[full];
int find(int s) {
int x = 0;
for (int i = s + 1; i <= 2 * n; i++)
if (f[i] == false) {
f[i] = true;
x = i;
break;
}
return x;
}
void process() {
for (int i = 1; i <= 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... | import javax.swing.*;
import java.awt.desktop.SystemSleepEvent;
import java.util.*;
import java.io.*;
public class Main {
public static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedRead... |
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 tick() {
static clock_t oldtick;
clock_t newtick = clock();
double diff = 1.0 * (newtick - oldtick) / CLOCKS_PER_SEC;
oldtick = newtick;
return diff;
}
long long gcd(long long a, long long b) {
if ((a == 0) || (b == 0)) {
return a + b;
}
return gc... |
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
Q = int(input())
Query = []
for _ in range(Q):
N = int(input())
A = list(map(int, input().split()))
Query.append((N, A))
for N, A in Query:
S = set(A)
C = set()
for n in range(1, 2*N+1):
if not n in S:
C.add(n)
ans = []
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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n), b(2 * n);
for (int &i : a) cin >> i;
set<int> s;
for (int i = 1; i <= 2 * n; i++) s.insert(i);
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... | 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... | #include <bits/stdc++.h>
using namespace std;
const int siz = 1e5 + 7;
const int siz2 = 2e5 + 7;
int t, n;
int a[222];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
A:
while (t--) {
cin >> n;
map<int, int> mp;
vector<int> Ans;
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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
import java.math.*;
public class Main {
static int mod = 1000000007;
/*****************code By... |
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())
test_cases = [(input(),input()) for i in range(t)]
def solve(test_case):
n = int(test_case[0])
b = list(map(int,test_case[1].split()))
c = [i for i in range(1,2*n+1) if i not in b]
a = []
for i in range(n):
a.append(b[i])
if c[-1] > b[i]:
tmp = min([c[... |
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 tc in range(int(input())):
n = int(input())
arr = []
d = {}
line = input().split()
for i in range(1, (2*n)+1):
d[i] = 1
for i in range(n):
arr.append(int(line[i]))
d[arr[i]] = 0
# print(d)
b = []
flag = 0
for i in range(n):
ele = arr[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;
const long long int mod = 1e9 + 7;
const double pie = 3.14159265358979323846;
const char nl = '\n';
const char spc = ' ';
template <typename Type>
istream &operator>>(istream &in, vector<Type> &v) {
long long int n = v.size();
for (int i = 0; i < n; i++) in >> v[i];
r... |
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.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;
... |
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.*;
public class Main{
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
... |
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... | Q = int(input())
for _ in range(Q):
n = int(input())
b = list(map(int, input().split()))
s = {*(range(2*n + 1))} - {*b}
a = []
try:
for i in b:
minn = min(s - {*range(i)})
s -= {minn}
a += i, minn
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... | t=int(input())
def f():
n=int(input())
b=list(map(int,input().split()))
a=[b[i//2] if i % 2==0 else 0 for i in range(n*2)]
used = 2*n*[0]+[0]
for i in a:
used[i] = 1
for i in range(1,2*n,2):
l = a[i-1]
j=l+1
while j<=2*n and used[j]:
j+=1
if 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;
inline long long read() {
char c = getchar();
long long f = 1, x = 0;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ '0');
c = getchar();
}
return x * f;
}
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... | # Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# 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 java.io.*;
import java.util.Arrays;
public class C {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = ne... |
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<bool> a(2 * n + 1);
vector<int> res(2 * n);
bool good = true;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
if (a[k] == false) {
a[k] = 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.*;
import java.util.*;
public class code {
static PrintWriter pw;
static boolean[] visit;
static ArrayList<Pair>[] adj;
static ArrayList<Integer> list;
static long max=01;
static void dfs(int i, long c) {
visit[i]=true;
max=Math.max(c, max);
for(Pair p: adj[i]) {
if(!visit[p.x-1]) {
df... |
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... | // practice with kaiboy
import java.io.*;
import java.util.*;
public class CF1315C extends PrintWriter {
CF1315C() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1315C o = new CF1315C(); o.main(); o.flush();
}
void main() {
int t = sc.nextInt();
while (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 java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Main implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private 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... | #include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
if (a % b == 0)
return b;
else {
return gcd(b, a % b);
}
}
inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
inline long long gaus(long long a, long long b) {
return (a + b) * (b - 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... | #include <bits/stdc++.h>
using namespace std;
signed main() {
long long int t = 1;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<long long int> b(n);
for (auto &x : b) cin >> x;
vector<bool> use(2 * n + 1, 0);
vector<long long int> a(2 * n + 1, 0);
for (auto x : b) use[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 t, n, m, k, ccnt, pos = 0, sum = 0, minn2 = INT_MAX, sum2, cnt2 = 0,
cnt3 = 0, cnt4 = 0, cnt5 = 0, cnt6 = 0, cnt7 = 0,
vis[100005], x1, y7, x2, y2, x3, y3, aaa, bbb;
long long a[1000005], b[1000005], c[100000... |
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=[int(x) for x in input().split()]
v=set(list(range(1,2*n+1)))
for x in b:
v.remove(x)
l=list(v)
l.sort()
ans=[-1 for _a in range(2*n)]
ok=True
for i in range(n):
ans[2*i]=b[i]
ok=False
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... | for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
s = set()
for i in range(1,2*n +1):
s.add(i)
for i in arr:
s.discard(i)
a = []
b = True
for i in arr:
if i+1>2*n:
b = False
else:
if i+1 in s:
a+=[i+1]
s.discard(i+1)
else:
c = False
for t in 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 sys
from collections import defaultdict, deque
inp = sys.stdin.readline
read = lambda: list(map(int, inp().split()))
def a():
ans = ""
for _ in range(read()[0]):
a, b, x, y = read()
x += 1
y += 1
ans += str(max(((a-x)*(b)), ((x-1)*(b)), ((a)*(b-y)), ((a)*(y-1)))) + "\n"
print(ans)
def c():
# 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 Restoring_Permutation
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for(int i=0;i<a;i++)
{
int n=sc.nextInt();
int data[] = new int[n];
int man[] = new int[2*n];
for(int j=0;j<n;j++)
{
data[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... |
def get_rank(input):
indices = list(range(len(input)))
indices.sort(key=lambda x: input[x])
output = [0] * len(indices)
for i, x in enumerate(indices):
output[x] = i
return output
cases = int(raw_input().strip())
for case in range(cases):
n = int(raw_input().strip())
b = map(int, raw_input().strip()... |
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 long long MOD = 1e9 + 7;
const long long INF = LLONG_MAX;
int main() {
int t;
cin >> t;
while (t--) {
int n, x, flag, m;
cin >> n;
x = 2 * n;
int a[x];
for (long long i = 0; i < (long long)x; i++) a[i] = i + 1;
vector<int> s;
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... | for i in range(int(input())):
n=int(input())
b=list(map(int,input().split()))
a=[]
flag=0
for j in range(n):
a.append(b[j])
k=b[j]
while k in a or k in b:
k+=1
if k>2*n:
print(-1)
flag=1
break
else:
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... | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int eps = 1e-8;
const long long mod = 1e9 + 7;
const long long maxn = 200 + 10;
const unsigned long long modd = 212370440130137957ll;
const long long Mod = 998244353;
int lowbit(int x) { return x & -x; }
long long gcd(long long a, 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... | t = int(input())
for _ in range(t):
n = int(input())
b = list(map(int, input().split()))
a = [0]*(2*n)
ok = True
for i in range(n):
a[i*2] = b[i]
while 0 in a:
moved = False
for i in range(1, 1+2*n):
ind = a.index(0)
if i not in a and 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.BigInteger;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class TP {
public static PrintWriter out;
public static FastReader in;
public static void main(String[] args) throws IOException {
long s = System.currentT... |
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
input=stdin.readline
for _ in range(int(input())):
n=int(input());m=2*n;v=[0]*m
a=list(map(int,input().split()))
if max(a)==m:print(-1)
else:
k=1;d=[]
for i in a:v[i-1]=1
for i in range(n):
d.append(a[i]);p=a[i]-1
while v[p]!=0:
p+=1
if p==m:print(-1);k=0;break
if not 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.util.Scanner;
import java.util.TreeSet;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
while(tc-- > 0) {
int n = sc.nextInt();
TreeSet<Integer> set = new TreeSet<>();
... |
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
import bisect
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().rstrip().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
t = ini()
for _ in range(t):
n = ini()
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... | #include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
void solve() {
int n;
cin >> n;
vector<pair<int, int>> m;
map<int, int> mp;
for (int j = 0; j < n; j++) {
int x;
cin >> x;
m.push_back({x, 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... | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
class SortedList:
def __init__(self, iterable=[], _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 main() {
int t;
cin >> t;
while (t--) {
int n, flag = 1;
cin >> n;
int a[201] = {0}, b[n], ans[2 * n];
for (int i = 0; i < n; i++) {
cin >> b[i];
a[b[i]] = 1;
}
if (a[1] == 0 || a[2 * n] == 1) {
cout << "-1\n";
conti... |
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)100;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
char dir[] = {'L', 'D', 'R', 'U'};
const long long int mod = (long long int)1e9 + 7;
const long long int inf = 1e18 + 100;
int BIT[100005], n;
long long int p... |
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() {
long long n;
cin >> n;
vector<long long> line(n);
for (long long& i : line) cin >> i;
set<long long> av;
for (long long i = 1; i <= 2 * n; i++) av.insert(i);
for (long long i : line) av.erase(i);
vector<long long> ans(2 * n);
for (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... | # Work hard. Complain harder. Unknown
# by : Blue Edge - Create some chaos
for _ in range(int(input())):
n=int(input())
b=list(map(int,input().split()))
a=[1]*(2*n+1)
for x in b:
a[x]=0
p=[]
res=True
for x in b:
p.append(x)
f=0
i=x+1
while i<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... | def solution():
for _ in range(int(input())):
n = int(input())
arr = [int(i) for i in input().split()]
maximal = max(arr)
minimal = min(arr)
mandatory = set(range(1, minimal+maximal+1))
if len(mandatory) > 2*n or minimal > 1:
print(-1)
continue... |
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 debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
const int maxn = 105;
long long n, m, k;
long long a[m... |
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.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class RestoringPermutation implements Closeable {
private InputReader in = new InputReader(System.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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.TreeSet;
public class Permutation {
public static void main(String[] args) throws IOException {
BufferedReader 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... | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main implements Runnable
{
boolean multiple = true;
long MOD;
@SuppressWarnings("Duplicates")
void solve() throws Exception
{
int n = sc.nextInt();
TreeSet<Integer> remaining = new TreeSet<>();
... |
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 long long mod = 1e9 + 7;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
set<int> s;
for (int i = 0; i < 2 * n; i++) s.insert(i + 1);
for (int i = 0; i < n; i++) {
cin >> a[i];
s.erase(a[i]);
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.