Problem:


Problem Statement

We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i.

At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly:

Choose a (connected) rope with a total length of at least L, then untie one of its knots.

Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.

Constraints

2≤N≤10^5

1≤L≤10^9

1≤a_i≤10^9

All input values are integers.

Input

The input is given from Standard Input in the following format:

N L
a_1 a_2 ... a_n

Output

If it is not possible to untie all of the N-1 knots, print Impossible.

If it is possible to untie all of the knots, print Possible, then print another N-1 lines that describe a possible order to untie the knots. The j-th of those N-1 lines should contain the index of the knot that is untied in the j-th operation. Here, the index of the knot connecting piece i and piece i+1 is i.

If there is more than one solution, output any.

Sample Input 1

3 50
30 20 10

Sample Output 1

Possible
2
1

If the knot 1 is untied first, the knot 2 will become impossible to untie.

Sample Input 2

2 21
10 10

Sample Output 2

Impossible

Sample Input 3

5 50
10 20 30 40 50

Sample Output 3

Possible
1
2
3
4

Another example of a possible solution is 3, 4, 1, 2.



Sample input:
3 50
30 20 10


Sample output:
Possible
2
1

Submission status: Wrong Answer

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

A = list(map(int, input().split()))

ans_index = -1
for i in range(N-1):
    if A[i] + A[i+1] >= L:
        ans_index = i
        break

if ans_index == -1:
    print('Impossible')
    exit()
print('Possible')
for i in range(N-1):
    if i == ans_index:
        continue
    print(i+1)

print(ans_index+1)

Submission status: Wrong Answer

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

A = list(map(int, input().split()))

ans_index = -1
for i in range(N-1):
    if A[i] + A[i+1] >= L:
        ans_index = i+1
        break

if ans_index == -1:
    print('Impossible')
    exit()
print('Possible')
for i in range(1, N):
    if i == ans_index:
        continue
    print(i)

print(ans_index)

Submission status: Wrong Answer

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

A = list(map(int, input().split()))

ans = 0
now_length = sum(A)

left_edge = 1
right_edge = N-1
solve = 0

processed = []

for _ in range(N-1):
    if A[0] < A[-1] and now_length >= L:
        tmp = A.pop(0)
        solve += 1
        processed.append(left_edge)
        left_edge += 1
        now_length -= tmp
    if A[-1] < A[0] and now_length >= L:
        tmp = A.pop(-1)
        solve += 1
        processed.append(right_edge)
        right_edge -= 1
        now_length -= tmp

    if now_length < L:
        break

if solve == (N-1):
    print('Possible')
    for p in processed:
        print(p)
else:
    print('Impossible')

Submission status: Wrong Answer

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

A = list(map(int, input().split()))

ans = 0
now_length = sum(A)

left_edge = 1
right_edge = N-1
solve = 0

processed = []

while N-1 > solve:
    if A[0] < A[-1] and now_length >= L:
        tmp = A.pop(0)
        solve += 1
        processed.append(left_edge)
        left_edge += 1
        now_length -= tmp
    if A[-1] < A[0] and now_length >= L:
        tmp = A.pop(-1)
        solve += 1
        processed.append(right_edge)
        right_edge -= 1
        now_length -= tmp

    if now_length < L:
        break

if solve == (N-1):
    print('Possible')
    for p in processed:
        print(p)
else:
    print('Impossible')

Submission status: Wrong Answer

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

A = list(map(int, input().split()))

ans = 0
now_length = sum(A)

left_edge = 1
right_edge = N-1
solve = 0

processed = []

while N-1 > solve:
    if A[0] < A[-1] and now_length >= L:
        A.pop(0)
        solve += 1
        processed.append(left_edge)
        left_edge += 1
    if A[-1] < A[0] and now_length >= L:
        A.pop(-1)
        solve += 1
        processed.append(right_edge)
        right_edge -= 1

    if now_length < L:
        break

if solve == (N-1):
    print('Possible')
    for i in range(len(processed)):
        print(processed[i])
else:
    print('Impossible')

Submission status: Wrong Answer

Solution code:
from collections import deque

n,l=map(int,input().split())
a=list(map(int,input().split()))

s=""

for i in range(1,n):
  if a[i-1]+a[i]>l:
    s="p"
    break

if s=="":
  print("Impossible")
  exit()
print("Possible")
  
for j in range(1,i):
  print(j)
for j in range(1,len(a)-i):
  print(len(a)-j)
  
print(i)

Submission status: Wrong Answer

Solution code:
from collections import deque

n,l=map(int,input().split())
a=list(map(int,input().split()))

s=""

for i in range(1,n):
  if a[i-1]+a[i]>l:
    s="p"
    break

if s=="":
  print("impossible")
  exit()
print("possible")
  
for j in range(1,i):
  print(j)
for j in range(1,len(a)-i):
  print(len(a)-j)
  
print(i)

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
As = list(map(int, input().split()))
l = []
i = 0
j = N-1
s = sum(As)
while i < j:
  if s < L:
    print("Impossible")
    exit()
  if As[i] < As[j]:
    l.append(i+1)
    s -= As[i]
    i += 1
  else:
    l.append(j)
    s -= As[j]
    j -= 1
print("Possible")
for i in l:
  print(i)

Submission status: Wrong Answer

Solution code:
from collections import deque

n,l=map(int,input().split())
a=list(map(int,input().split()))

sumA=sum(a)
lenA=len(a)

dequeA=deque(a)
cnt=1
cntBack=lenA-1
result=[]

for _ in range(n):
  if lenA>1:
    #print(dequeA)
    if sumA>=l:
      LL=dequeA.popleft()
      RR=dequeA.pop()
      if LL>RR:
        result.append(cntBack)
        cntBack-=1
        dequeA.appendleft(LL)
        sumA-=RR
      else:
        result.append(cnt)
        cnt+=1
        dequeA.append(RR)
        sumA-=LL
      lenA-=1
    else:
      print("Impossible")
      exit()
  else:
    break

print("Possible")
for item in result:
  print(item)

Submission status: Wrong Answer

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

ma=-1
mi=-1
for i in range(N-1):
  if a[i]+a[i+1]>ma:
    mi=i
    ma=a[i]+a[i+1]

if ma>=L:
  print("Possible")
  for i in range(N-1):
    if(i!=mi):
      print(i+1)
  print(mi+1)
else:
  print("Impossible")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#AGC2 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,l = LI()
a = LI()
tmp = 0
inde = 0
for i in range(1,n):
  if tmp < a[i] + a[i-1]:
    tmp = a[i]+a[i-1]
    inde = i
if tmp < l:
  print('Impossible')
  quit()
print('Possible')
ans = [i for i in range(1,n)]
ans.remove(inde)
ans.append(inde)
for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,l = inpl()
a = inpl()
aa = []
for i in range(1,n):
    aa.append([i,a[i-1] + a[i]])
# print(aa)
if n == 2: 
    if a[0] + a[1] < l:
        print('Impossible')
        quit()
    else:
        print('Possible')
        print(1)
elif n == 3:
    if max(aa[1]) < l:
        print('Impossible')
        quit()
    else:
        aa.sort(key=lambda x:x[1])
    print('Possible')
    for i in range(n-1):
        print(aa[i][0])
else:
    for i in range(n-3):
        if max(aa[i:i+3][1]) < l:
            print('Impossible')
            break
    else:
        aa.sort(key=lambda x:x[1])
        print('Possible')
        for i in range(n-1):
            print(aa[i][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,l = inpl()
a = inpl()
flag = -1
for i in range(1,n):
    if a[i] + a[i-1] >= l:
        flag = i
        print('Possible')
        for j in range(1,n):
            if j == flag:
                continue
            else:
                print(j)
        print(flag)
        break
else:
    print('Impossible')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(200000)
n,l=map(int,input().split())
r=list(map(int,input().split()))
last=0;tiepoint=0
for i in range(n-1):
  if r[i]+r[i+1]>last:
    last=r[i]+r[i+1]
    tiepoint=i
if last>=l:
  print("Possible")
  for i in range(tiepoint-1):
    print(i+1)
  for i in range(tiepoint+1,n-1)[::-1]:
      print(i+1)
  print(tiepoint+1)
else:print("Impossible")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(200000)
n,l=map(int,input().split())
r=list(map(int,input().split()))
last=0;tiepoint=0
for i in range(n-1):
  if r[i]+r[i+1]>last:
    last=r[i]+r[i+1]
    tiepoint=i
if last>=l:
  print("Possible")
  for i in range(tiepoint-1):
    print(i+1)
  for i in range(tiepoint+1,n)[::-1]:
      print(i+1)
  print(tiepoint+1)
else:print("Impossible")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(200000)
n,l=map(int,input().split())
r=list(map(int,input().split()))
last=0;tiepoint=0
for i in range(n-1):
  if r[i]+r[i+1]>last:
    last=r[i]+r[i+1]
    tiepoint=i
if last>=l:
  print("Possible")
  for i in range(n-1):
    if i==tiepoint:continue
    print(i+1)
  print(tiepoint+1)
else:print("Impossible")

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
*A, = map(int, input().split())
for i, (a1, a2) in enumerate(zip(A, A[1:])):
    if a1 + a2 >= L:
        print('Possible')
        print(*([j+1 for j in range(i)]+[j+1 for j in range(i+1, N-1)]+[i+1]), sep='\n')
        break
else:
    print('Impossible')

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
*A, = map(int, input().split())
length = sum(A)
order = []
i, j = 0, N-1
while length >= L and len(order) < N-1:
    if A[i] < A[j]:
        length -= A[i]
        order.append(i+1)
        i += 1
    else:
        length -= A[j]
        order.append(j)
        j -= 1
if len(order) == N-1:
    print('Possible')
    print(*order, sep='\n')
else: print('Impossible')

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
r=list(map(int,input().split()))
last=0;tiepoint=0
for i in range(n-1):
  if r[i]+r[i+1]>last:
    last=r[i]+r[i+1]
    tiepoint=i
if last>=l:
  print("Possible")
  for i in range(n-1):
    if i==tiepoint:continue
    print(i+1)
  print(tiepoint+1)
else:print("Impossible")

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
r=list(map(int,input().split()))
last=0;tiepoint=0
for i in range(n-1):
  if r[i]+r[i+1]>last:
    last=r[i]+r[i+1]
    tiepoint=i
if last>=l:
  print("Possible")
  for i in range(n-1):
    if i==tiepoint:continue
  print(i+1)
else:print("Impossible")

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
r=list(map(int,input().split()))
last=0;tiepoint=0
for i in range(n-1):
  if r[i]+r[i+1]>last:
    last=r[i]+r[i+1]
    tiepoint=i
if last>=l:
  print("Possible")
  for i in range(n-1):
    if i==tiepoint:continue
  print(i)
else:print("Impossible")

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
r=list(map(int,input().split()))
last=0;tiepoint=0
for i in range(n-1):
  if r[i]+r[i+1]>last:
    last=r[i]+r[i+1]
    tiepoint=i
if last>=l:
  print("Possible")
  for i in range(n):
    if i==tiepoint:continue
  print(i)
else:print("Impossible")

Submission status: Wrong Answer

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

for i in range(n-1):
    if a[i]+a[i+1] >= l:
        print("Possible")
        for j in range(1,i+1):
            print(j)
        for k in range(i,n-1):
            print(k+1)
        exit()
print("Impossible")

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
import math
import time
ts=time.time()
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n,l=MI()
a=LI()
ans='Impossible'
an=[]
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        ans='Possible'
        an+=[i+1]
        break

print(ans)
if ans=='Possible':
    an+=list(range(an[0]+1,n))
    an+=list(range(1,an[0]))
    for i in an[::-1]:
        print(i)

Submission status: Wrong Answer

Solution code:
N, L = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
l, i = max((A[i] + A[i - 1], i) for i in range(1, N))
ans = []
if l >= L:
    print('Possible')
    if i < N - 1:
        ans += list(range(i, N))
        ans += list(range(1, i))
        ans = ans[::-1]
    else:
        ans += list(range(1, i + 1))
    print(*ans, sep='\n')
else:
    print('Impossible')

Submission status: Wrong Answer

Solution code:
N, L = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
l, i = max((A[i] + A[i - 1], i) for i in range(1, N))
ans = []
if l >= L:
    print('Possible')
    if i < N - 1:
        ans += list(range(i, N))
        ans += list(range(1, i))
        ans = ans[::-1]
    else:
        ans += list(range(1, i + 1))
        ans = ans[::-1]
    print(*ans, sep='\n')
else:
    print('Impossible')

Submission status: Wrong Answer

Solution code:
N,L=map(int,input().split())
A=list(map(int,input().split()))
x=-1
for i in range(N-1):
    if A[i]+A[i+1]>=L:
        x=i
        break
if x==-1:
    print('Impossible')
else:
    print('Possible')
    r=list(range(1,x+1))+list(range(x+2,N))+[x+1,]
    print(*r,sep='\n')

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
L = list(map(int,input().split()))
flag = False
cur = 0
for i in range(n-1):
    if L[i]+L[i+1] >= l:
        flag = True
        cur = i+1
        break
if flag:
    print('Possible')
    for i in range(1,n):
        if cur != i:
            print(i)
    print(cur)
else:
    print('Impossible')

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
L = list(map(int,input().split()))
s = 0
e = n-1
flag = True
k = 0
total = sum(L)
ans = []
while k < n-1:
    if total >= l:
        k += 1
        if L[s] <= L[e]:
            total -= L[s]
            s += 1
            ans.append(s)
        else:
            total -= L[e]
            e -= 1
            ans.append(e+1)
    else:
        flag = False
        break
if flag:
    print('Possible')
    for i in range(n-1):
        print(ans[i])
else:
    print('Impossible')

Submission status: Wrong Answer

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

key = 0
flag = False
for i in range(n-1):
    if arr[i] + arr[i+1] >= l:
        key = [i,i+1]
        flag = True
        break

# print(key)
if flag:
    for i in range(key[0]):
        print(i+1)
    temp = []
    for i in range(key[1]+1,n):
        temp.append(i)
    temp.reverse()
    for t in temp:
        print(t)
    print(key[1])

else:
    print("Impossible")

Submission status: Wrong Answer

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

key = 0
flag = False
for i in range(n-1):
    if arr[i] + arr[i+1] >= l:
        key = [i,i+1]
        flag = True
        break

# print(key)
if flag:
    for i in range(key[0]):
        print(i+1)
    for i in range(n-1,key[1],-1):
        print(i)
    print(key[1])

else:
    print("Impossible")

Submission status: Wrong Answer

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

key = 0
flag = False
for i in range(n-1):
    if arr[i] + arr[i+1] >= l:
        key = [i,i+1]
        flag = True
        break

# print(key)
if flag:
    for i in range(key[0]):
        print(i+1)
    for i in range(key[1]+1,n):
        print(i)
    print(key[1])

else:
    print("Impossible")

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
arr = list(map(int,input().split()))
ext = [[i,arr[i]] for i in range(n)]
ext.sort(key=lambda x:x[1])

if ext[-1][1] + ext[-2][1] < l:
    print("Impossible")
else:
    print("Possibble")
    resolved = set()
    resolved.add(0)
    resolved.add(n)
    for i in range(n):
        left = ext[i][0]
        right = left+1
        if left not in resolved:
            print(left)
            resolved.add(left)
        if right not in resolved:
            print(right)
            resolved.add(right)

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, l = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    s = sum(a)
    for i in range(1, n):
        if a[i] + a[i-1] >= l:
            print("Posible")
            for j in range(1, i):
                print(j)
            for j in range(n-1, i, -1):
                print(j)
            print(i)
            exit()
    print("Impossible")


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, l = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    s = sum(a)
    f = 0
    b = 1
    ans = []
    while True:
        if s >= l:
            if a[f] <= a[-b]:
                s -= a[f]
                f += 1
                ans.append(f)
            else:
                s -= a[-b]
                b += 1
                ans.append(n - b + 1)
            if f == n - b:
                print("Possible")
                print(*ans, sep="\n")
                exit()
        else:
            print("Impossible")
            exit()


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, l = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    s = sum(a)
    aa = []
    for i, v in enumerate(a):
        aa.append([v, i])
    aa.sort()
    ans = []
    for v, i in aa:
        if s - v >= l:
            ans.append(i+1)
        else:
            print("Impossible")
            exit()
    print(*ans[:-1], sep="\n")


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
# AGC002C - Knot Puzzle
def main():
    N, L = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    B = sorted((a + b, i) for i, (a, b) in enumerate(zip(A, A[1:]), 1))
    length, ans = zip(*B)
    if length[-1] >= L:
        print("Possible")
        print(*ans, sep="\n")
    else:
        print('Impossible')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# AGC002C - Knot Puzzle
def main():
    N, L = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    # length = [i + j for i, j in zip(A, A[1:])]
    if sum(A) < L:
        print("Impossible")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
a = [int(i) for i in input().split()]
b = []
for i in range(n-1):
    b.append(a[i] + a[i+1])
if max(b) >= l:
    ans = "Possible"
else:
    ans = "Impossible"
print(ans)
if ans == "Possible":
    k = b.index(max(b))
    ans = [i+1 for i in range(n-1) if i != k]
    ans.append(k+1)
    for i in ans:
        print(i)

Submission status: Wrong Answer

Solution code:
N,L,*A=map(int,open(0).read().split())
k=-1
for i in range(N-1):
	if A[i]+A[i+1]>=L:
		k=i
if k>=0:
	print('Possible')
	for i in range(k+1,N-1):
		print(i+1)
	for i in range(k+1):
		print(i+1)
else:
	print('Impossible')

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
A=[int(i) for i in input().split()]

wa=[A[i]+A[i+1] for i in range(n-1)]
lim=max(wa)
knot=wa.index(lim)

go=False
if l<=lim:
    print("Possible")
    go=True
else:
    print("Impossible")
    
if go:
    for i in range(knot):
        print(i+1)
    for i in range(n-knot-2):
        print(n-i)
    print(knot+1)

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
A=[int(i) for i in input().split()]

wa=[A[i]+A[i+1] for i in range(n-1)]
lim=max(wa)
knot=wa.index(lim)

go=False
if l<lim:
    print("Possible")
    go=True
else:
    print("Impossible")
    
if go:
    for i in range(knot):
        print(i+1)
    for i in range(n-knot-2):
        print(n-i)
    print(knot+1)

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
A=[int(i) for i in input().split()]

wa=[A[i]+A[i+1] for i in range(n-1)]
lim=max(wa)

if l<lim:
    print("Possible")
else:
    print("Impossible")

Submission status: Wrong Answer

Solution code:
n,l,*a=map(int,open(0).read().split())
i=m=0
for j,(x,y)in enumerate(zip(a,a[1:]),1):
  if x+y>m:
    m=x+y
    i=j
if m<l:
  print('Impossible')
else:
  print('Possible')
  print(*range(1,i))
  print(*range(i+1,n))
  print(i)

Submission status: Wrong Answer

Solution code:
N,L = map(int,input().split())
*A, = map(int,input().split())

S = [0]*(N+1)
for i,a in enumerate(A): S[i+1] = S[i] + a
ans = []
i=0
j=N-1
while i<j:
    if S[j+1]-S[i] < L:
        print("Impossible")
        break
    if A[i] <= A[j]:
        ans.append(i+1)
        i+=1
    else:
        ans.append(j)
        j-=1
else:
    print("Possible")
    for a in ans: print(a)

Submission status: Wrong Answer

Solution code:
import math
N,L = list(map(int,input().split(" ")))
As= list(map(int,input().split(" ")))
right = len(As) - 1
left = 0
anss = []
s = sum(As)
imp = False
while True:



    if As[right] > As[left]:
        s -= As[left]
        anss.append(left + 1)
        left+=1
    else:
        s -= As[right]
        anss.append(right)
        right -= 1

    if s < L:
        print("Impossible")
        exit()
    if right - left == 1:
        anss.append(left + 1)
        break
print("Possible")
for i in anss:
    print(i)

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
a = list(map(int, input().split()))
ma = 0
midx = 0
for i in range(n - 1):
  if ma < a[i] + a[i + 1]:
    midx = i
    ma = a[i] + a[i + 1]
if l > ma:
  print('Impossible')
else:
  print('Posiible')
  for i in range(midx):
    print(i + 1)
  for i in range(n - 1, midx, -1):
    print(i)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, L = map(int, input().split())
A = list(map(int, input().split()))

large_pair = -1
# 一つでもA[i]+A[i+1]>=Lとなるところが存在すれば、そこを最後まで残して、他を全部解けばいい
for i in range(N-1):
    if A[i]+A[i+1] >= L:
        large_pair = i
        break

if large_pair == -1:
    ans = "Impossible"
    print(ans)
else:
    # 解く順を逆から辿っていく
    ans = "Possible"
    order = [large_pair]
    for a in range(large_pair):
        order.append(a)
    for a in range(large_pair+1, N-1):
        order.append(a)

    print(ans)
    print("\n".join(map(lambda x: str(x+1), reversed(order))))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, L = map(int, input().split())
A = list(map(int, input().split()))

ans = "Possible"
large_pair = -1
for i in range(N-1):
    if A[i]+A[i+1] >= L:
        large_pair = i
        break
if large_pair == -1:
    ans = "Impossbile"
    print(ans)
else:
    order = [large_pair]
    start = large_pair
    left = start-1
    right = start+1

    while left >= 0:
        order.append(left)
        left -= 1

    while right < N-1:
        order.append(right)
        right += 1

    print(ans)
    print("\n".join(map(lambda x: str(x+1), reversed(order))))

Submission status: Wrong Answer

Solution code:
n, L = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
st = -1
for i in range(n-1):
    if a[i] + a[i+1] >= L:
        st = i
        break
if st < 0:
    print("Impossible")
else:
    print("Possible")
    for i in range(n-1):
        if i != st:
            print(i+1)
    print(st+1)

Submission status: Wrong Answer

Solution code:
n, L = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
l, r = 0, n-1
ans = []
for i in range(n-1):
    if s < L:
        print("Impossible")
        quit()
    if a[l] < a[r]:
        ans.append(str(l+1))
        s -= a[l]
        l += 1
    else:
        ans.append(str(r))
        s -= a[r]
        r -= 1
print("Possible" + "\n" + "\n".join(ans))

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
r = list(map(int,input().split()))
o = 0
flag = 1
for i in range(1,n):
    lr = r[i-1] +r[i]
    if lr >= l:
        o = i
        flag = 0
        break
if flag == 0:
    for j in range(1,o):
        print(j)
    for k in range(n-1,o,-1):
        print(k)
    print(o)
else:
    print('Impossible')

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
r = list(map(int,input().split()))
o = 0
flag = 1
for i in range(1,n):
    lr = r[i-1] +r[i]
    if lr > l:
        o = i-1
        flag = 0
        break
if flag == 0:
    for j in range(1,o):
        print(j)
    for k in range(n-1,o,-1):
        print(k)
    print(o)
else:
    print('Impossible')

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
A=[int(i) for i in input().split()]
length,knot=A[0]+A[1],1
for i in range(n-2):
  if A[i+1]+A[i+2]>length:
    length=A[i+1]+A[i+2]
    knot=i+2
if length<50:
  print("Impossible")
else:
  print("Possible")
  for i in range(1,knot):
    print(i)
  for i in range(knot,n):
    print(n+knot-i-1)

Submission status: Wrong Answer

Solution code:
#AGC002C 12:56:40-12:58:20-
import copy

N, L = map(int, input().split())
a = list(map(int, input().split()))
b = copy.copy(a)
a.sort()
res = []
print(a)
print(b)

while (len(a) > 0):
    if (sum(a) < L):
        print("Impossible")
        break
        
    idx = b.index(a[0])
    res.append(idx+1)
    a.pop(0)
else:
    print("Possible")
    for r in res: print(r)

Submission status: Wrong Answer

Solution code:
#AGC002C 12:56:40-12:58:20-
N, L = map(int, input().split())
a = list(map(int, input().split()))
res = []

while (len(a) > 0):
    if (sum(a) < L):
        print("Impossible")
        break
        
    idx = a.index(min(a))
    a.pop(idx)
    res.append(idx)
else:
    print("Possible")
    for r in res: print(r)

Submission status: Wrong Answer

Solution code:
n,l = [int(i) for i in input().split()]
a=[int(i) for i in input().split()]
#b=[int(i) for i in input().split()]

max_len   = a[0]+a[1]
max_joint = 1

for i in range(1,n-1):
    len = a[i] + a[i+1]
    if len > max_len:
        max_len   = len
        max_joint = i+1


if max_len < l:
    print("Impossible")
    exit()
else:
    print("Possible")
    for i in range(1,max_joint):
        print(i)
    for i in range(n, max_joint, -1):
        print(i)
    print(max_joint)

Submission status: Wrong Answer

Solution code:
n,l = [int(i) for i in input().split()]
a=[int(i) for i in input().split()]
#b=[int(i) for i in input().split()]

max_len   = a[0]+a[1]
max_joint = 1

for i in range(1,n-1):
    len = a[i] + a[i+1]
    if len > max_len:
        max_len   = len
        max_joint = i+1


if max_len < l:
    print("Impossible")
    exit()
else:
    print("Possible")
    for i in range(1,max_joint):
        print(i)
    for i in range(n, max_joint, -1):
        print(i)
    print("Possible")

Submission status: Wrong Answer

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

preva = alist[0]
is_possible = False
for i, a in enumerate(alist[1:]):
  if preva + a >= l:
    is_possible = True
    break
  preva = a

if not is_possible:
  print('Impossible')
else:
  for j in range(1, i+1):
    print(j)
  for j in range(n-1, i+1, -1):
    print(j)
  print(i + 1)

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n-1):
  if a[i] + a[i+1] >= l:
    print("Possible")
    break
else:
  print("Impossible")
  exit()
li = [range(1,i+1)]+[range(n,i+1,-1)]+[i+1]
print(" ".join(map(str, li)))

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i]+a[i+1] for i in range(n-1)]
start = -1
for ind, length in enumerate(b):
    if length >= l:
        start = ind+1
        break
if start<0:
    print("Impossible")
else:
    print("Ppossible")
    for i in range(1,start):
        print(i)
    for i in range(start, n)[::-1]:
        print(i)

Submission status: Wrong Answer

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

judge = "Impossible"
for i in range(N - 1):
	x = a[i] + a[i + 1]
	if x >= L:
		judge = "Possible"
		c = i + 1
		break


if judge == "Impossible":
	print(judge)
else:
	print(judge)
	for i in range(1, c):
		print(i)
	for i in range(c + 1, N):
		print(i)
	print(c)

Submission status: Wrong Answer

Solution code:
N, L = map(int,input().split())
a = list(map(int,input().split()))
t = True
key_number = -1
for i in range(1,N):
    if a[i] + a[i-1] >= L:
        t = False
        key_number = i

if t:
    print("Impossible")
else:
    print("Possible")
    for ans in range(1,i-1):
        print(ans)
    for ans in range(N-1,i-2,-1):
        print(ans)

Submission status: Wrong Answer

Solution code:
N, L = map(int,input().split())
a = list(map(int,input().split()))
A = sum(a)
left = 1
right = N-1
Ans = []
append = Ans.append
while right - left >= 0:
    if A < L:
        print("Impossible")
        exit()
    if a[left] < a[right]:
        append(left)
        A -= a[left]
        left += 1
    else:
        append(right)
        A -= a[right]
        right -= 1

print("Possible")
for ans in Ans:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
A=list(map(int,input().split()))
for i in range(n-1):
    if A[i]+A[i+1]>=l:
        print('Possible')
        break
else:
    print('Impossible')

Submission status: Wrong Answer

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

renzoku_length = [0]*n
last_undo = -1
for i in range(1,n):
  renzoku_length[i] = a[i]+a[i-1]
  if renzoku_length[i]>=l:
    last_undo =i
    break

if last_undo ==-1:
  print("Impossible")
  exit()

print("Possible")
for i in range(1,last_undo):
  print(i)
for i in range(last_undo+1,n):
  print(i)
print(last_undo)