Problem:


Score : 400 points

Problem Statement

Snuke has an empty sequence a.

He will perform N operations on this sequence.

In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).

You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq b_i \leq N

Input

Input is given from Standard Input in the following format:

N
b_1 \dots b_N

Output

If there is no sequence of N operations after which a would be equal to b, print -1.
If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.

Sample Input 1

3
1 2 1

Sample Output 1

1
1
2

In this sequence of operations, the sequence a changes as follows:

After the first operation: (1)

After the second operation: (1,1)

After the third operation: (1,2,1)

Sample Input 2

2
2 2

Sample Output 2

-1

2 cannot be inserted at the beginning of the sequence, so this is impossible.

Sample Input 3

9
1 1 1 2 2 1 2 3 2

Sample Output 3

1
2
2
3
1
2
2
1
1



Sample input:
3
1 2 1


Sample output:
1
1
2

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(b) for b in input().split()]

L = []

while B:
    idx = N+1
    for i in range(len(B)):
        if B[i] == i+1:
            continue
        else:
            idx = i-1
            break
    if idx < 0:
        break
    elif idx == N+1:
        idx = len(B)-1
    L.append(B[idx])
    B.pop(idx)

if B:
    print(-1)
else:
    L.reverse()
    for l in L:
        print(l)

Submission status: Wrong Answer

Solution code:
n = int(input())
B = list(map(int, input().split()))
ret = []

def get_latest():
  for i in range(len(B)):
    if len(B) - i == B[len(B) - i - 1]:
      break
  ret.append(B.pop(len(B) - i - 1))
  if B:
    get_latest()

get_latest()
for i in range(n):
  print(ret[n - i - 1])

Submission status: Wrong Answer

Solution code:
n = int(input())
B = list(map(int, input().split()))
ret = [-1] * n
ng = False
for i in range(n):
  p = n - i - 1
  found = False
  for j in range(B[p] - 1, min(n, n - (p - B[p] + 2) + 1)):
    if ret[j] < 0:
      ret[j] = B[p]
      found = True
      break
  if not found:
    ng = True
    break

if ng:
  print(-1)
else:
  for i in range(n):
    print(ret[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
x=[0]
inp=input().split()
for k in range(N):
  x.append(int(inp[k]))
def rec(x,y):
  if len(x)==1:
    print(y)
    return y
  OK=False
  for i in range(len(x)-1,0,-1):
    if x[i]==i:
      del x[i]
      y.insert(0,i)
      rec(x,y)
      OK=True
      break
  if OK==False:
    print(-1)
    return -1
rec(x,[])

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
b = [int(i) for i in input().split()]

def find(j):
    for i in range(n):
        if b[i] == j + 1:
            return i
    return -1

flag = False
tmp = []
for i in range(n):
    if b[i] > i + 1:
        print(-1)
        sys.exit()

arr = []
for i in range(n):
    arr.append([find(i), b[i]])
print(arr)
arr.sort()
for i in range(n):
    print(arr[i][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
A = []
ans = -1
for i in range(N):
  if B[i] <= i+1:
    A.append(B[i])
  else:
    break
    
if (len(A) == len(B)):
  for i in A:
    print(i)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
A = []
ans = -1
for i in range(N):
  if B[i] <= i+1:
    A.append(B[i])
  else:
    break
    
if (len(A) == len(B)):
  print(*A)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
for i in range(n)[::-1]:
  if i+1<b[i]:
    print(-1)
    exit()
b.sort()
for i in b:
  print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
ans = []

for i in range(n):
    k = n-i
    for j in range(n)[::-1]:
        if b[j] == k:
            b[j] = 0
            ans.append(k)
            break
        if b[j] != 0: k -= 1
    else:
        ans = [-1]
        break

for i in ans[::-1]: print(i)

Submission status: Wrong Answer

Solution code:
N=int(input())
b=sorted(list(map(int,input().split())))
for i in range(N):
  if b[i]>i+1:
    print(-1)
    break
else:
  for i in range(N):
    print(b[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
B = list(map(int, input().split()))

B.sort()

for idx, b in enumerate(B):
    if b > idx + 1:
        print(-1)
        exit()

for b in B:
    print(b)

Submission status: Wrong Answer

Solution code:
# AGC032 A - Limited Insertion
n=int(input())
b=list(map(int,input().split()))

for i in range(n):
    if b[i]>i+1:
        print(-1)
        exit()

if max(b)>n:
    print(-1)
    exit()
idx=[]
#Trueが＋
pm_flg=False

idx.append(0)
for i in range(n-1):
    if b[i+1]>b[i] and pm_flg==False:
        if i==0:continue
        pm_flg=True
        idx.append(i)
    elif b[i+1]<b[i] and pm_flg==True:
        pm_flg=False
idx.append(n)
L=[]
for i in range(len(idx)-1):
    l=[]
    for j in range(idx[i],idx[i+1]):
        l.append(b[j])
    L.append(l)
# print(idx)
# print(L)
L.sort(reverse=True)
# print(L) 
M=[]
for i,l in enumerate(L):
    M.append([min(l),i])
M.sort()
# print(L)
# print(M)
for i,l in enumerate(L):
    # この辺のソートが多分おかしい
    # L[M[i][1]].sort()
    l=L[M[i][1]]
    l.sort()
    for ll in l:
        print(ll)

Submission status: Wrong Answer

Solution code:
# AGC032 A - Limited Insertion
n=int(input())
b=list(map(int,input().split()))

for i in range(n):
    if b[i]>i+1:
        print(-1)
        exit()

if max(b)>n:
    print(-1)
    exit()
idx=[]
#Trueが＋
pm_flg=False

idx.append(0)
for i in range(n-1):
    if b[i+1]>b[i] and pm_flg==False:
        if i==0:continue
        pm_flg=True
        idx.append(i)
    elif b[i+1]<b[i] and pm_flg==True:
        pm_flg=False
idx.append(n)
L=[]
for i in range(len(idx)-1):
    l=[]
    for j in range(idx[i],idx[i+1]):
        l.append(b[j])
    L.append(l)
# print(idx)
# print(L)
L.sort(reverse=True)
# print(L) 
M=[]
for i,l in enumerate(L):
    M.append([min(l),i])
M.sort()

for i,l in enumerate(L):
    L[M[i][1]].sort()
    for ll in l:
        print(ll)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
if b[0]!=1:
    print(-1)
    exit()
x=[[0]]
judge=1
k=0
for i in range(1,n):
    if b[i]==1:
        x.append([i])
        judge=1
        x[k].append(i)
        k+=1
    else:
        judge+=1
        if b[i]>judge:
            print(-1)
            exit()
        if b[i-1]>=b[i]:
            x[k].append(i)
x[-1].append(n)
x.reverse()
k+=1
for i in range(k):
    print(1)
    t=len(x[i])
    x[i].reverse()
    for j in range(1,t):
        for p in range(x[i][j],x[i][j-1]):
            if b[p]!=1:
                print(b[p])

Submission status: Wrong Answer

Solution code:
for i in range(1,100):
  print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int,input().split()))
ans = []
for i in range(N):
    for j in range(len(b)-1,-1,-1):
        if b[j] <= j+1:
            ans.append(b[j])
            b.pop(j)
            break
if len(ans) == N:
    for i in ans:
        print(i)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
b=list(map(int,input().split()))

a=[]
while b:
    f=True
    if b[0]!=1:
        print(-1)
        exit()
    if len(b)==1:
        a.append(b.pop())
        break
    for i in range(1,len(b)):
        if b[i]!=i+1:
            temp=b.pop(i-1)
            a.append(temp)
            f=False
            break

    if f:
        a.append(b.pop())
        
for i in range(N):
    print(a[-1*(i+1)])

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
b = [b[0]] + b[1:][::-1]

ans = []
for i, j in enumerate(b):
    if i + 2 < j:
        print(-1)
        exit()
    else:
        ans.append(str(j))
print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
b = tuple(map(int, input().split()))

a = [0] * N

for i in range(N):
    a[i] = (i + 1) - b[i]

ans = []
mi = 1
c = 1
temp = 0
owari = -1 * N
while sum(a) != owari:
    mi = 100
    temp = 0
    temp2 = 0
    for i in range(N):
        if mi >= b[i] and a[i] != -1:
            mi = b[i]
            temp = i
            temp2 = a[i]
    if mi > c:
        print(-1)
        sys.exit()
    ans.append(mi)
    a[temp] = -1
    c += 1
    while max(a[temp:]) >= temp2:
        ma = temp
        for i in range(temp,N):
            if a[ma] < a[i]:
                ma = i
        if a[ma] == -1:
            break
        if b[ma] > c:
            print(-1)
            sys.exit()
        ans.append(b[ma])
        a[ma] = -1
        c += 1
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
b = tuple(map(int, input().split()))

a = [0] * N

for i in range(N):
    a[i] = (i + 1) - b[i]

ans = []
mi = 1
c = 1
temp = 0
owari = -1 * N
while sum(a) != owari:
    mi = 100
    temp = 0
    temp2 = 0
    for i in range(N):
        if mi >= b[i] and a[i] != -1:
            mi = b[i]
            temp = i
            temp2 = a[i]
    if mi > c:
        print(-1)
        sys.exit()
    ans.append(mi)
    a[temp] = -1
    c += 1
    while max(a[temp:]) >= temp2:
        ma = temp
        for i in range(temp,N):
            if a[ma] < a[i]:
                ma = i
        if ma == -1:
            break
        if b[ma] > c:
            print(-1)
            sys.exit()
        ans.append(b[ma])
        a[ma] = -1
        c += 1
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
b = sorted(list(map(int, input().split())))
ans = 1
for k,v in enumerate(b):
  k += 1
  if k < v:
    ans = 0
    break
if ans:
  for i in b:
    print(i)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import permutations

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = list(permutations(li, n))
flag = 0
for i in lin:
    i = list(i)
    lis = []
    for j in range(n):
        lis.insert(i[j]-1,i[j])
    if lis == li:
        flag = 1
        break
if flag == 1:
    for i in lis:
        print(i)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = []
for i in range(n):
    if i+1 >= li[i]:
        lin.append(li[i])
    else:
        print(-1)
        exit()
for i in lin:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    key = 0
    for j in range(0,i):
      if b[j] == j+1:
        key = j+1
      elif j == i-1 and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    for j in range(0,i):
      key = 0
      if b[j] == j+1:
        key = j+1
      elif j == i-1 and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(map(int,input().split()))
LIST=list("")

for i in range(N):
    if((S[i] - i)>1):
        print("-1")
        exit()  

while(len(S)>0):
    M=max(S)
    S.remove(M)
    LIST.append(M)

for i in range(N):
    print(LIST[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(map(int,input().split()))
LIST=list("")

for i in range(N):
    if((S[i] - i)>1):
        print("-1")
        exit()  

while(len(S)>0):
    M=max(S)
    S.remove(M)
    LIST.append(M)

for i in range(len(LIST)-1,-1,-1):
    print(LIST[i])

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
tmp=(n+1)//2*(n-2)
# print(tmp)
if n%2==0:
    print(n*(n-2)//2)
else:
    print(((n-1)*(n-3))//2+n-1)
for i in range(n):
    for j in range(i+1,n):
        if (i+1)+(j+1)!=n+(n+1)%2:
            print(i+1,j+1)

Submission status: Wrong Answer

Solution code:

N = int(input())
b = list(map(int, input().split()))
a = []

for i in range(N):
    tmp = -1
    for j in range(N - i):
        if b[j] == j + 1:
            tmp = j
            continue
        else:
            break
    if tmp != -1:
        a.append(b.pop(tmp))

if len(a) == N:
    for i in range(N - 1, -1, -1):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
#print(b)

for i in range(N):
    if b[i] > i+1:
        print("-1")
        exit()
dict = {}

for i in range(N):
    if b[i] not in dict:
        dict[b[i]] = 1
    else:
        dict[b[i]] += 1

#print(dict)

for key in dict:
    while(dict[key] > 1):
        if dict[key] > 1:
            print(key)
            dict[key] -= 1

for key in dict:
    print(key)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
#print(b)

for i in range(N):
    if b[i] > i+1:
        print("-1")
        exit()
dict = {}

for i in range(N):
    if b[i] not in dict:
        dict[b[i]] = 1
    else:
        dict[b[i]] += 1

print(dict)

for key in dict:
    while(dict[key] > 1):
        if dict[key] > 1:
            print(key)
            dict[key] -= 1

for key in dict:
    print(key)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
#print(b)

for i in range(N):
    if b[i] > i:
        print("-1")
        exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
print(b)

for i in range(N):
    if b[i] > i:
        print("-1")
        exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
ans = []
for i in reversed(range(n)):
    for j in reversed(range(i+1)):
        if b[j]==j+1:
            ans.append(b[j])
            b.pop(j)
            print(b)
            break

        if j==0:
            print(-1)
            exit()
for i in reversed(range(n)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = [0]*n
if b[0]!=1:
    print(-1)
    exit()
a[0] = b[0]
for i in range(1,n):
    if b[i]==1:
        a[i]=1
    else:
        a[i] = b[i]
        for j in range(i):
            if a[j]==0:
                print(-1)
                exit()
a.sort()
for i in range(n):
    print(a[i])

Submission status: Wrong Answer

Solution code:
n=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(n):
    for j in range(len(B))[::-1]:
        if B[j]==j+1:
            A.append(B.pop(j))
            break
    else:print(-1);break
for i in A[::-1]:print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(n):
    for j in range(len(B))[::-1]:
        if B[j]==j+1:
            A.append(B.pop(j))
            break
for i in A[::-1]:print(i)

Submission status: Wrong Answer

Solution code:
import copy

N=int(input())
a = list(map(int,input().split()))


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
            
        for i in temp[::-1]:
            root.append(i)
            string.pop(i-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)

Submission status: Wrong Answer

Solution code:
import copy

N=int(input())
a = list(map(int,input().split()))


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        for i in temp[::-1]:
            root.append(i)
            string.pop(i-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root:
        print(i)

Submission status: Wrong Answer

Solution code:
import copy

N=int(input())
a = list(map(int,input().split()))


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        for i in temp[::-1]:
            root.append(i)
            string.pop(i-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)

Submission status: Wrong Answer

Solution code:
import copy
import sys

sys.setrecursionlimit(200000000)

N=int(input())
a = list(map(int,input().split()))

# def dfs(string, root):
#     temps = [i+1 for i in range(len(string))]
#     output=-1
#     if len(string)==0:
#         return root
    
#     for i,s in enumerate(string):
#         if i+1==s:
#             temp_root = copy.deepcopy(root)
#             temp_string=copy.deepcopy(string)
#             temp_root.append(i+1)
#             temp_string.pop(i)
#             temp = dfs(temp_string, temp_root)
            
#             if temp!=-1:
#                 output=temp
#                 break
#     return output

root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        for i in temp[::-1]:
            root.append(i)
            string.pop(i-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root:
        print(i)

Submission status: Wrong Answer

Solution code:
import copy
import sys

sys.setrecursionlimit(200000000)

N=int(input())
a = list(map(int,input().split()))
values = set(a)

dicts={}
def dfs(string, root):
    temps = [i+1 for i in range(len(string))]
    output=-1
    if len(string)==0:
        return root
    
    for i,s in enumerate(string):
        if i+1==s:
            temp_root = copy.deepcopy(root)
            temp_string=copy.deepcopy(string)
            temp_root.append(i+1)
            temp_string.pop(i)
            temp = dfs(temp_string, temp_root)
            
            if temp!=-1:
                output=temp
    return output

output=dfs(a, [])

output

if isinstance(output, list):
    for i in output:
        print(i)
else:
    print(output)

Submission status: Wrong Answer

Solution code:
import copy
import sys

sys.setrecursionlimit(200000000)

N=int(input())
a = list(map(int,input().split()))
values = set(a)

dicts={}
def dfs(index, string, values, N, root):
    temp=[]
    if index == N:
        dicts[" ".join(list(map(str,string)))] = root
        return None
    
    length = len(string)+1
    
    for i in values:

        if i > index:
            break
        temp_str = copy.deepcopy(string)
        temp_root = copy.deepcopy(root)
        temp_str.insert(i,i)
        temp_root.append(i)
        
        dfs(index+1, temp_str, values, N, temp_root)
        

        

dfs(1,[], values, N+1, [])

output = " ".join(list(map(str,a)))

if output in dicts:
    for i in dicts[output]:
        print(i)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
a = list(map(int,input().split()))


import copy
import sys

sys.setrecursionlimit(200000000)

values = set(a)

dicts={}
def dfs(index, string, values, N, root):
    temp=[]
    if index == N:
        dicts[" ".join(list(map(str,string)))] = root
        return None
    
    for i in values:
        temp_str = copy.deepcopy(string)
        temp_root = copy.deepcopy(root)
        temp_str.insert(i,i)
        temp_root.append(i)
        
        dfs(index+1, temp_str, values, N, temp_root)
        

        

dfs(1,[], values, N+1, [])

output = " ".join(list(map(str,a)))

if output in dicts:
    for i in dicts[output]:
        print(i)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
B = list(map(int,input().split()))

L = [[] for i in range(n)]

for i in reversed(range(n)):
    if 0 <= n-1-(i+1-B[i]) < n:
        L[n-1-(i+1-B[i])] += [B[i]]
    else:
        print(-1)
        exit()

A = [0 for i in range(n)]

H = []
for i in reversed(range(n)):
    for j in range(len(L[i])):
        heapq.heappush(H,-L[i][j])
    A[i] = -heapq.heappop(H)

for i in range(n):
    if i+1 < A[i]:
        print(-1)
        exit()

for a in A:
    print(a)

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()

ans = []

for i in range(n):
    for j in range(len(b)):
        if b[j] == j + 1:
            ans.append(b[j])
            del b[j]
            break
        if j == 0:
            print(-1)
            exit()

print(' '.join([str(_) for _ in reversed(ans)]))

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()


def insert(bl, l, lo):

    if l is None:
        return
    if len(l) == n:
        if l == b:
            return 1, lo
        return
    for i in range(len(bl)):

        if len(l) < bl[i]-1:
            return
        ll = [li for li in l]
        ll.insert(bl[i] - 1, bl[i])
        res = insert(bl[0:i] + bl[i+1:n], ll, lo+[bl[i]])
        if res is not None:
            return res


ans = insert(b, [], [])
if ans:
    print(' '.join([str(s) for s in ans[1]]))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import heapq

N=int(input())
l=list(map(int,input().split()))
temp=[]

if l[0]!=1:
    print(-1)

for i in range(len(l))[::-1]:
    if l[i]>=i:
        print(-1)
        exit()
    temp.append(l.pop(-1))
    if temp[-1]==1:
        heapq.heapify(temp)
        while temp:
            print(heapq.heappop(temp))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import heapq

N=int(input())
l=list(map(int,input().split()))
temp=[]

if l[0]!=1:
    print(-1)

for i in range(len(l))[::-1]:
    temp.append(l.pop(-1))
    if temp[-1]==1:
        heapq.heapify(temp)
        while temp:
            print(heapq.heappop(temp))

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split()))

used = [False] * n
res = []


def f(left, index):
    for i in reversed(range(index, n)):
        if not used[i] and ls[i] == left + 1:
            used[i] = True
            res.append(ls[i])
            f(left + 1, i)


f(0, 0)
if len(res) == n:
    print(*res, sep='\n')
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
b=list(map(int,input().split()))
b.sort()

for i in range(N):
    if b[i]>i+1:
        print(-1)
        exit()

for i in range(N):
    print(b[i])

Submission status: Wrong Answer

Solution code:
N,B=open(0);*B,=map(int,B.split());print(*(B*all(b<i for i,b in enumerate(B,2))or[-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
for i, b in enumerate(B, 1):
    if i < b:
        print(-1)
        exit()

d = []
for i in range(N-1, -1, -1):
    d.append(B[i])
    if B[i] == 1:
        for x in sorted(d):
            print(x)
        d = []

Submission status: Wrong Answer

Solution code:
n = int(input())
B = list(map(int, input().split()))
flag = False
for i in range(n):
  if B[i]+1 > i:
    flag = True
if flag:
  print(-1)
else:
  for j in range(n):
    print(B[j])

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int,input().split()))
ans=[]
while len(B)>0:
    tmp = -1
    for i in range(len(B)):
        if i+1 < B[i]:
            print(-1)
            exit()
        elif i+1 == B[i]:
            tmp = i
        else:
            break
    ans.append(B[tmp])
    del B[tmp]
for a in reversed(ans):
    print(a)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    B = list(map(int, input().split()))
    for i in range(N):
        if B[i] > i+1:
            return False, None
    else:
        i = 1
        ops = []
        while i < N:
            temp = []
            while i < N and B[i] != 1:
                temp.append(B[i])
                i += 1
            temp = [[temp[i], i+1-temp[i]] for i in range(len(temp))]
            temp.sort(key = lambda x: x[1], reverse = True)
            temp = [temp[i][0] for i in range(len(temp))]
            temp = [1] + temp
            ops += temp[::-1]
            i += 1
        if B[-1] == 1:
            ops += [1]
        return True, ops[::-1]

if __name__ == '__main__':
    output = main()
    if output[0] == False:
        print(-1)
    else:
        for v in output[1]:
            print(v)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    B = list(map(int, input().split()))
    for i in range(N):
        if B[i] > i+1:
            return False, None
    else:
        i = 1
        ops = []
        while i < N:
            temp = []
            while i < N and B[i] != 1:
                temp.append(B[i])
                i += 1
            temp = [[temp[i], i+1-temp[i]] for i in range(len(temp))]
            temp.sort(key = lambda x: x[1], reverse = True)
            temp = [temp[i][0] for i in range(len(temp))]
            temp = [1] + temp
            ops += temp[::-1]
            i += 1
        return True, ops[::-1]

if __name__ == '__main__':
    output = main()
    if output[0] == False:
        print(-1)
    else:
        for v in output[1]:
            print(v)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    B = list(map(int, input().split()))
    for i in range(N):
        if B[i] > i+1:
            return False, None
    else:
        ops = []
        visited = set()
        while len(visited) < N:
            min_v = float("inf")
            min_i = None
            for i in range(N-1, -1, -1):
                if i not in visited:
                    if B[i] < min_v:
                        min_i = i
                        min_v = B[i]
            visited.add(min_i)
            ops.append(min_v)
            d = dict()
            for i in range(min_i+1, N):
                if i not in visited and B[i] <= min_v + 1:
                    visited.add(i)
                    min_v = B[i]
                    ops.append(min_v)
            # print(visited)
        return True, ops

if __name__ == '__main__':
    output = main()
    if output[0] == False:
        print(-1)
    else:
        for v in output[1]:
            print(v)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

N = int(input())
B = list(map(int, input().split()))

B.sort()
for i,b in enumerate(B):
    if i+1 < b:
        print(-1)
        exit()

for b in B:
    print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input().split())
seq = []


for i in range(n):
    m = -1
    for j in range(len(s)):
        if int(s[j]) == j+1:
            m = j
    if m != -1:
        s = s[:m]+s[m+1:]
        seq.append(m+1)

print(s)
# print(seq)

if len(s) == 0:
    for i in range(1,n+1):
        print(seq[-i])
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(input().split())
s = "".join(b)
seq = []


for i in range(n):
    m = -1
    for j in range(len(s)):
        if int(s[j]) == j+1:
            m = j
    if m != -1:
        s = s[:m]+s[m+1:]
        seq.append(m+1)
    # print(s)

# print(s)
# print(seq)

if len(s) == 0:
    for i in range(1,n+1):
        print(seq[-i])
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(input().split())
s = "".join(b)
seq = []


for i in range(n):
    m = -1
    for j in range(len(s)):
        if int(s[j]) == j+1:
            m = j
    if m != -1:
        s = s[:m]+s[m+1:]
        seq.append(m+1)
    # print(s)

# print(s)
# print(seq)

if s == "":
    for i in range(1,n+1):
        print(seq[-i])
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(input().split())
s = "".join(b)
seq = []


for i in range(n):
    m = -1
    for j in range(len(s)):
        if int(s[j]) == j+1:
            m = j
    if m != -1:
        s = s[:m]+s[m+1:]
        seq.append(m+1)

# print(s)
# print(seq)

if s == "":
    for i in range(1,n+1):
        print(seq[-i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))

#成り立たせることができるかどうか
for i in range(1, N + 1):
    if b[i - 1] > i:
        print (-1)
        exit()


check_lst = [False] * N #i番目の数を使ったかどうか

ans_lst = [] #答えの逆順
for i in range(N - 1, -1, -1):
    if check_lst[i]: #True --> 既に使ったとき
        continue #次のiから続ける
    count = b[i] - 1
    index = i - 1
    # print ('count', count)
    # print ('index', index)
    while count > 0:
        if b[index] < b[i] and b[index] <= len(ans_lst) + 1: #次に入れたいやつより小さくて、iより大きいもの
            count -= 1
            # print ('B')
            if check_lst[index] == False:
                check_lst[index] = True
                # print (b[index])
                ans_lst.append(b[index])
        index -= 1
        if index < 0:
            index = i - 1
    ans_lst.append(b[i])
    check_lst[i] = True

for i in ans_lst:
    print (i)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

N = int(input())
c = Counter(list(map(int, input().split())))
t = 1
for i in range(1, N+1)[::-1]:
    if t < c[i]:
        print(-1)
        exit()
    t += 1-c[i]
if t > 1:
    print(-1)
    exit()
for i in range(1, N+1):
    for j in range(c[i]):
        print(i)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

N = int(input())
c = Counter(list(map(int, input().split())))
t = 1
for i in range(1, N+1)[::-1]:
    if t < c[i]:
        print(-1)
        exit()
    t += 1-c[i]
if t > 1:
    print(-1)
    exit()
for i in range(1, N):
    for j in range(c[i]):
        print(i)