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: Accepted

Solution code:
n,l=map(int,input().split())
a=list(map(int,input().split()))
ok=False
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        ok=True
        idx=i
if ok:
    print("Possible")
    for i in range(1,idx+1):
        print(i)
    for i in reversed(range(idx+2,n)):
        print(i)
    print(idx+1)
else:
    print("Impossible")

Submission status: Accepted

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

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')
    for i in range(x):
        print(i+1)
    for i in range(n-2,x,-1):
        print(i+1)
    print(x+1)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, l = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = [a[i] + a[i + 1] for i in range(n - 1)]

    last = -1
    for i, x in enumerate(b, 1):
        if x >= l:
            last = i
            break

    if last == -1:
        print("Impossible")
    else:
        print("Possible")
        for i in range(1, last):
            print(i)
        for i in range(n - 1, last, -1):
            print(i)
        print(last)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = list(map(int, input().split()))
ans = float("inf")
for i in range(n - 1):
    if a[i] + a[i + 1] >= l:
        ans = i + 1
if ans == float("inf"):
    print("Impossible")
else:
    print("Possible")
    print(*range(1, ans), sep="\n")
    print(*range(n - 1, ans, -1), sep="\n")
    print(ans)

Submission status: Accepted

Solution code:
import sys

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):
        idx = i
        break
else:
    print("Impossible")
    sys.exit()
    
print("Possible")

for i in range(1, i+1):
    print(i)
    
for i in range(N-1, i, -1):
    print(i)

Submission status: Accepted

Solution code:
# 隣り合う和がL未満ならそもそもimpossible
# ならば隣り合う和がL以上ならば？ -> そこから連続して隣り合うやつをどうやって足しても常にL以上

n, l = map(int, input().split())
a = list(map(int, input().split()))
idx = 0
for i in range(1, n):
    if a[i - 1] + a[i] >= l:
        idx = i
        break
if idx == 0:
    print("Impossible")
    exit()

print("Possible")

ans = [idx]
for i in range(idx - 1, 0, -1):
    ans.append(i)
for i in range(idx + 1, n):
    ans.append(i)
for a in ans[::-1]:
    print(a)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,l=map(int,input().split())
a=list(map(int,input().split()))
I,P="Impossible","Possible"

for i in range(n-1):
    if a[i]+a[i+1]>=l:
        print(P)
        for j in range(i):
            print(j+1)
        for j in range(i+1,n)[::-1]:
            print(j)
        break
else:
    print(I)

Submission status: Accepted

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

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

if idx == -1:
  print("Impossible")
else:
  print("Possible")
  for i in range(idx):
    print(i + 1)
  for i in range(N - 1, idx, -1):
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
n, l = map(int, input().split())
a = list(map(int, input().split()))
last = -1
for i in range(1,n):
    if a[i-1] + a[i] >= l :
        last = i
if last == -1:
    print("Impossible")
else:
    print("Possible")
    for i in range(1, last):
        print(i)
    for i in range(n-1,last,-1):
        print(i)
    print(last)

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
As = list(map(int, input().split()))
# 和がl以上のものがあれば、それを残してあとを端から落としていくのでよい
ss = [As[i]+As[i+1] for i in range(n-1)]
# print(ss)
cnt = 0
for i,s in enumerate(ss):
    if s >= l:
        cnt = i + 1
if cnt == 0:
    print("Impossible")
    exit()
print("Possible")
for i in range(1,cnt):
    print(i)
for i in range(n-1, cnt, -1):
    print(i)
print(cnt)

Submission status: Accepted

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

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

# 2個でL以上の隣合うペアがどこかにあれば、そこを最後に残せば大丈夫
target = -1
for i in range(1,len(A)):
  if A[i] + A[i - 1] >= L:
    target = i
    break
if target == -1:
  print("Impossible")
  exit(0)

left = []
for i in range(1,target):
  left.append(i)
  
right = []
for i in range(len(A) - 1,target,-1):
  right.append(i)

print("Possible")
for l in left:
  print(l)
for r in right:
  print(r)
print(target)

Submission status: Accepted

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, L, A):
    for i in range(N - 1):
        if A[i] + A[i + 1] >= L:
            break
    else:
        print('Impossible')
        return
    print('Possible')
    for j in range(N - 1):
        if j == i:
            break
        print(j + 1)
    for j in range(N - 2, -1, -1):
        if j == i:
            break
        print(j + 1)
    print(i + 1)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, L = map(int, input().split())
    *A, = map(int, input().split())
    main(N, L, A)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = list(map(int, input().split()))
ind = -1
for i in range(n-1):
    if a[i]+a[i+1] >= l:
        ind = i
        break

if ind == -1:
    print("Impossible")
else:
    print("Possible")
    for i in range(ind):
        print(i+1)
    for i in range(n-1, ind, -1):
        print(i)

Submission status: Accepted

Solution code:
import sys
import os

N, L, *A = map(int, os.read(0, 10**8).split())

def main(L, A):
    N = len(A)
    is_long = [x + y >= L for x, y in zip(A, A[1:])]
    if not any(is_long):
        print('Impossible')
        return
    print('Possible')
    i = is_long.index(True)
    nums = list(range(1, i + 1)) + list(range(N - 1, i, -1))
    print(*nums, sep='\n')

main(L, A)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, L = MAP()
a = LIST()

for i in range(N-1):
    if a[i]+a[i+1] >= L:
        idx = i
        break
else:
    print("Impossible")
    exit()

print("Possible")

for i in range(1, i+1):
    print(i)

for i in range(N-1, i, -1):
    print(i)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, L, *A = map(int, read().split())

def main(L, A):
    N = len(A)
    is_long = [x + y >= L for x, y in zip(A, A[1:])]
    if not any(is_long):
        print('Impossible')
        return
    print('Possible')
    i = is_long.index(True)
    nums = list(range(1, i + 1)) + list(range(N - 1, i, -1))
    print(*nums, sep='\n')

main(L, A)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,l=mp()
a=lmp()
c=True
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        c=False
        ind=i
        break
if c:
    print("Impossible")
    exit()
print("Possible")
for i in range(1,ind+1):
    print(i)
for i in range(n-1,ind+1,-1):
    print(i)
print(ind+1)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,l = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    pa = a[0]
    mi = -1
    for i,ai in enumerate(a[1::]):
        if pa+ai >= l:
            print("Possible")
            mi = i
            break
        pa = ai
    if mi == -1:
        print("Impossible")
        exit()
    for i in range(mi):
        print(i+1)
    for i in range(n-mi-1):
        print(n-i-1)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if flag==0:
    print("Impossible")
else:
    print("Possible")
    if i>0:
        for j in range(1,i+1):
            print(j)
    if i+2<n:
        tmp=[]
        for j in range(i+2,n):
            tmp.append(j)
        for item in tmp[::-1]:
            print(item)
    print(i+1)

Submission status: Accepted

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

for i in range(1, N):
    if A[i-1]+A[i] >= L:
        print('Possible')
        ans = []
        for j in range(1, i):
            ans.append(j)
        for k in range(N-1, i, -1):
            ans.append(k)
        ans.append(i)
        print(*ans, sep='\n')
        exit()
print('Impossible')

Submission status: Accepted

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

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

if flg == 0:
    print('Impossible')
else:
    print('Possible')
    last += 1
    # x = list(range(last+1,N))
    x = list(range(N-1,last,-1))
    y = list(range(1,last))
    for a in x:
        print(a)
    for a in y:
        print(a)

    print(last)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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:
        ans = ["Possible"]
        ans += [j for j in range(1,i+1)]
        ans += [j for j in range(n-1, i+1, -1)]
        ans.append(i+1)
        break
else:
    ans = ["Impossible"]
write("\n".join(map(str, ans)))

Submission status: Accepted

Solution code:
n,l=map(int, input().split())
*a,=map(int, input().split())
mx=0
ind=-1
for i in range(n-1):
    if mx<=a[i+1]+a[i]:
        ind=i
        mx=a[i+1]+a[i]
if mx>=l:
    print("Possible")
    for i in range(ind):
        print(i+1)
    for i in range(n-1,ind,-1):
        print(i)
else:
    print("Impossible")

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
A=list(map(int, input().split()))
x=0
for i in range(N-1):
  d=A[i]+A[i+1]
  if d>=L:
    x=1
    knot=i+1
    break
    
if x==0:
  print('Impossible')
  exit()

print('Possible')
for i in range(1,knot):
  print(i)
for i in range(N-1,knot-1,-1):
  print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, l = map(int, input().split())
    a = list(map(int, input().split()))
    f = False
    idx = -1
    for i in range(n-1):
        if a[i] + a[i+1] >= l:
            f = True
            idx = i+1
            break
    if f:
        print("Possible")
        for i in range(1, idx):
            print(i)
        for i in reversed(range(idx+1, n)):
            print(i)
        print(idx)
    else:
        print("Impossible")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,l=NM()
a=[0]+L()
for i in range(1,n):
    if a[i]+a[i+1]>=l:
        print("Possible")
        for j in range(1,i):
            print(j)
        for j in range(n-1,i-1,-1):
            print(j)
        break
else:
    print("Impossible")

Submission status: Accepted

Solution code:
K=10**10
import sys
N,L=map(int,input().split())
T=list(map(int,input().split()))
for i in range(N-1):
  if T[i]+T[i+1]>=L:
    K=i
    print("Possible")
    break
if K==10**10:
  print("Impossible")
  sys.exit()
K=K+1
R=list(range(1,K))
M=list(range(K+1,N))
M.reverse()
R.extend(M)
R.append(K)
for i in range(N-1):
  print(R[i])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,L=map(int,input().split())
    a=tuple(map(int,input().split()))
    for i in range(N-1):
        if a[i]+a[i+1]>=L:
            print('Possible')
            for j in range(i):
                print(j+1)
            for j in range(N-2,i,-1):
                print(j+1)
            print(i+1)
            break
    else:
        print('Impossible')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = list(map(int, input().split()))
l = max_2 = A[0] + A[1]
idx = 0
for i in range(N-2):
  l += A[i+2] - A[i]
  if l > max_2:
    max_2 = l
    idx = i + 1

if max_2 < L:
  print('Impossible')
else:
  print('Possible')
  for i in range(1, idx + 1):
    print(i)
  for i in range(N-1, idx, -1):
    print(i)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
a = [int(i) for i in input().split()]
for i in range(n-1):
  if a[i]+a[i+1] >= l:
    print('Possible')
    for j in range(n-1,i+1,-1):
      print(j)
    for k in range(1,i+2):
      print(k)
    exit()
print('Impossible')

Submission status: Accepted

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

Submission status: Accepted

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

a=[int(x) for x in input().split()]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,L = inputIL()
A = inputIL()



for index in range(N):
  if index == 0:
    if A[0]+A[1] >= L:
      print("Possible")
      for i in range(N-1)[::-1]:
        print(i+1)
      exit()

  elif index == N-1:
    if A[N-1]+A[N-2] >= L:
      print("Possible")
      for i in range(N-1):
        print(i+1)
      exit()      

  else:
    if A[index]+A[index-1] >= L:
      print("Possible")
      for i in range(index,N-1)[::-1]:
        print(i+1)
      for i in range(index):
        print(i+1)
      exit()
    elif A[index]+A[index+1] >= L:
      print("Possible")
      for i in range(index):
        print(i+1)
      for i in range(index,N-1)[::-1]:
        print(i+1)
      exit()

print("Impossible")

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
a = [int(x) for x in input().split()]

ans = False
for i in range(N-1):
    if a[i] + a[i+1] >= L:
        ans = True
        break
if ans:
    print('Possible')
    for j in range(i):
        print(j+1)
    for j in range(N-2, i-1, -1):
        print(j+1)
else:
    print('Impossible')

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
flag=False
for i in range(0,n-1):
    if not flag:
        if a[i]+a[i+1]>=l:
            cnt=i+1
            flag=True

if not flag:
    print("Impossible")
    exit()

ans=[cnt]

for i in range(cnt-1,0,-1):
    ans.append(i)
for i in range(cnt+1,n):
    ans.append(i)
ans=ans[::-1]
print("Possible")
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
INF = 10 ** 15
MOD = 10 ** 9 + 7 
def main():
    N,L = map(int,input().split())
    A = list(map(int,input().split()))
    point = -1
    for i in range(N - 1):
        if A[i] + A[i + 1] >= L:
            point = i + 1
            break
    if point == - 1:
        print('Impossible')
        return
    ans = []
    for i in range(point - 1):
        ans.append(i + 1)
    for i in range(N - 2,point - 1,-1):
        ans.append(i + 1)
    ans.append(point)
    print('Possible')
    print('\n'.join(map(str,ans)))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

N, L = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().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 j in range(i+1, N)[::-1]:
            print(j)
        sys.exit()

print("Impossible")

Submission status: Accepted

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

max_i = 0
max_two_ropes = 0
for i in range(n - 1):
    two_ropes = aaa[i] + aaa[i + 1]
    if max_two_ropes < two_ropes:
        max_i = i
        max_two_ropes = two_ropes

if max_two_ropes < l:
    print('Impossible')
else:
    print('Possible')
    ans = list(range(1, max_i + 1))
    ans.extend(range(n - 1, max_i + 1, -1))
    ans.append(max_i + 1)
    print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n , l = IN()
	#s = input()
	al = LIN()
	for i in range(len(al)-1):
		if al[i]+al[i+1] >= l:
			break
	else:
		print('Impossible')
		return 
	print('Possible')
	last_tie = i + 1
	pa(('lt',last_tie))
	for i in range(1, last_tie):
		print(i)
	for i in range(n-1, last_tie, -1):
		print(i)
	print(last_tie)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

target = -1
for i in range(n-1):
    if al[i] + al[i+1] >= l:
        target = i

if target == -1:
    print("Impossible")
    exit()
else:
    print("Possible")
    for i in range(target):
        print(i+1)
    for i in range(n-1, target+1, -1):
        print(i)
    print(target+1)

Submission status: Accepted

Solution code:
import sys
n, l = map(int, input().split())
a = [int(x) for x in input().split()]

key = -1
for i in range(n-1):
  if a[i]+a[i+1] >= l:
    key = i
    break

if key == -1:
  print("Impossible")
else:
  print("Possible")
  for i in range(key):
    print(i+1)
  for i in range(n-1, key, -1):
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


def f(S, T):
    N = len(S)
    F = [[0 for _ in range(N)] for __ in range(N)]
    
    for i in range(N):
        for j in range(N):
            SS = S[i]
            TT = T[j]
            if TT == (0, 0):
                F[i][j] = 1 if SS == (0, 1) else 0
            elif TT == (0, 1):
                if SS == (1, 0):
                    return None
                F[i][j] = 1
            elif TT == (1, 0):
                if SS == (0, 1):
                    return None
                F[i][j] = 0
            else:
                F[i][j] = 0 if SS == (1, 0) else 1

    return F


def main():
    N, L = read_values()
    A = read_list()

    r = 0
    for i in range(N - 1):
        if A[i] + A[i + 1] >= L:
            r = i
            break
    else:
        print("Impossible")
        return

    print("Possible")
    
    for i in range(r):
        print(i + 1)
    for i in range(N - 2, r - 1, -1):
        print(i + 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, l = LI()
A = LI()
ret = 0
j = 0
for i in range(n - 1):
    if A[i] + A[i + 1] > ret:
        ret = A[i] + A[i + 1]
        j = i

if ret >= l:
    print('Possible')
    for k in range(j):
        print(k + 1)
    for m in range(n - 1, j + 1, -1):
        print(m)
    print(j + 1)
else:
    print('Impossible')

Submission status: Accepted

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')
  for i in range(x):
    print(i+1)
  for i in range(n-2,x,-1):
    print(i+1)
  print(x+1)

Submission status: Accepted

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

x=-1
for i in range(0,N-1):
    if a[i]+a[i+1]>=L:
        x=i
        break
if x==-1:
    print("Impossible")
else:
    print("Possible")
    for i in range(N-1, x+1,-1):
        print(i)
    for i in range(0,x+1):
        print(i+1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, l = LI()
    a = LI()
    for i in range(n - 1):
        if a[i] + a[i + 1] >= l:
            x = i
    try:
        ans = []
        for j in range(x):
            ans.append(j + 1)
        for j in range(n - 2, x - 1, -1):
            ans.append(j + 1)
        print("Possible")
        print("\n".join(map(str, ans)))
    except:
        print("Impossible")
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

flg = False
ans = []
for i in range(n-1):
    if a[i] + a[i+1] >= l:
        ans = [j for j in range(1, i+1)] + [j for j in range(n-1, i+1, -1)] + [i+1]
        flg = True
        break
    
if flg:
    print('Possible')
    print(*ans, sep='\n')
else:
    print('Impossible')

Submission status: Accepted

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

for i in range(0,N-1):
    if A[i]+A[i+1]>=L:
        print('Possible')
        for j in range(1,i+1):
            print(j)
        T=[]
        for j in range(i+2,N):
            T.append(j)
        T.sort(reverse=True)
        for j in range(0,len(T)):
            print(T[j])
        print(i+1)
        break
else:
    print('Impossible')

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
A=list(map(int,input().split()))
if N==2:
  if sum(A)>=L:
    print('Possible')
    print(1)
  else:
    print('Impossible')
  exit(0)
lasti=-1
for i in range(N-1):
  if A[i]+A[i+1]>=L:
    lasti=i+1
    break
if lasti==-1:
  print('Impossible')
else:
  print('Possible')
  for i in range(1,lasti):
    print(i)
  for i in range(N-1,lasti-1,-1):
    print(i)

Submission status: Accepted

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

sumax=0
for i in range(n-1):
    if sumax < a[i]+a[i+1]:
        sumax=a[i]+a[i+1]
        ind=i

if sumax < l:
    print("Impossible")
    exit()

print("Possible")

for i in range(1,n):
    if i>ind:
        break
    print(i)

for i in reversed(range(n)):
    if i==ind:
        break
    print(i)