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 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    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")
        return

    for j in range(1,i+1):
        print(j)
    for j in range(n-1,i,-1):
        print(j)
resolve()

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


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

A = np.array(A, dtype=int)

s = A[1:] + A[:-1]

if s.max() >= L:
    print('Possible')
    last = s.argmax()
    ans = list(range(N - 1))
    for i in range(last):
        print(i + 1)
    for i in reversed(range(last + 1, N - 1)):
        print(i + 1)
    print(last + 1)
else:
    print('Impossible')

Submission status: Accepted

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

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

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

#possible
if imp==0:
    print("Possible")
    for j in range(i):
        print(j+1)
    for j in range(N-1,i+1,-1):
        print(j)
    print(i+1)

Submission status: Accepted

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')
        ans = list(range(1,i+1))+list(range(i+2,n))[::-1]
        ans.append(i+1)
        for i in ans:
            print(i)
        exit()
print('Impossible')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

#####################################


#4:25
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
maxv=0
maxid=-1
for i in range(n-1):
    if(maxv<a[i]+a[i+1]):
        maxv=a[i]+a[i+1]
        maxid=i+1

if(maxv<k):
    print("Impossible")
    exit()
print("Possible")
for j in range(maxid-1):
    print(j+1)
    
for j in range(n-maxid-1):
    print(n-1-j)
    
print(maxid)

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(i) :
            print(j + 1)
        for j in range(N - 2, i, -1) :
            print(j + 1)
        print(i + 1)
        break
else :
    print('Impossible')

Submission status: Accepted

Solution code:

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

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

flag = False
able = 0
for i in range(N-1):

    if a[i] + a[i+1] >= L:
        flag = True
        able = i
        break

if flag:

    print ("Possible")

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

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

    #print (able + 1)

else:
    print ("Impossible")

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
a = [int(c) for c in input().split()]
m = 10**9
j = -1
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(N-1, i+1, -1):
      print(j)
    print(i+1)
    break
else:
  print('Impossible')

Submission status: Accepted

Solution code:
import numpy as np
n,l=map(int,input().split())
a=list(map(int,input().split()))
flag=False;idx=0
for i in range(n-1):
  if a[i]+a[i+1]>=l:
    flag=True
    idx=i
if not flag:
  print("Impossible")
  exit(0)
print("Possible")
for x in range(idx):
  print(x+1)
for x in reversed(range(idx,n-1)):
  print(x+1)

Submission status: Accepted

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

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

if ok:
    print('Possible')
    for j in range(1, i):
        print(j)
    for j in range(N-1, i, -1):
        print(j)
    print(i)
else:
    print('Impossible')

Submission status: Accepted

Solution code:
# 解説見た

from itertools import tee


def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


def solve(N, L, a):
    for knot, pair in enumerate(pairwise(a), 1):
        if sum(pair) >= L:
            break
    else:
        return []
        # 隣接和は全てL未満のため、最後の一つを外せない

    ans = []
    for i in range(1, knot):
        ans.append(i)
    for i in range(N - 1, knot - 1, - 1):
        ans.append(i)
    return ans


if __name__ == '__main__':
    N, L = map(int, input().split())
    a = tuple(map(int, input().split()))
    ans = solve(N, L, a)
    if ans:
        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()))
x = N
for i in range(1,N):
    if a[i] + a[i-1] >= L:
        x = i
if x == N:
    print('Impossible')
    exit()
print('Possible')
for i in range(1,x):
    print(i)
for i in range(N-1,x-1,-1):
    print(i)

Submission status: Accepted

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

r = [0]
for i in range(n):
    r.append(r[i] + a[i])

ansl = []
p,q = 0,n-1
suma = sum(a)
while p < q:
    if r[q+1] - r[p]  < L:
        print("Impossible")
        exit()
    if a[p] + a[p + 1] <= a[q-1] + a[q]:
        ansl.append(p + 1)
        p+=1
    else:
        ansl.append(q)
        q-=1


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

Submission status: Accepted

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(i):print(j+1)
    for j in range(n-1,i,-1):print(j)
    exit()
print("Impossible")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
N, L = map(int, input().split())
a = list(map(int, input().split()))
res = []
for i in range(N - 1):
  if a[i] + a[i + 1] >= L:
    res.append(i + 1)
    break
if len(res):
  i = res[0] - 1
  while i > 0:
    res.append(i)
    i -= 1
  i = res[0] + 1
  while i < N:
    res.append(i)
    i += 1
  print("Possible")
  for i in range(N - 2, -1, -1):
    print(res[i])
else:
  print("Impossible")

Submission status: Accepted

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

s = 0
for i in range(N-1):
    if A[i] + A[i+1] > s:
        s = A[i] + A[i+1]
        ind = i

if s < L:
    print('Impossible')
else:
    print('Possible')
    for i in range(N-1):
        if i == ind:
            break
        print(i+1)
    for i in reversed(range(N-1)):
        if i == ind:
            break
        print(i+1)
    print(ind+1)

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")
        exit()
    else:
        print("Impossible")
        exit()
ans=[]
for i in range(N-1):
    if A[i]+A[i+1]>=L:
        last=i
        for j in range(i):
            ans.append(j)
        for j in range(N-2,i,-1):
            ans.append(j)
        break

if len(ans)==0:
    print("Impossible")
    exit()

ans.append(last)

print("Possible")
for i in range(N-1):
    print(ans[i]+1)

Submission status: Accepted

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

pos = -1

for i in range(n-1):
    if a[i] + a[i+1] >= l:
        pos = i
        break
if pos == -1:
    print('Impossible')
    exit()

print('Possible')
for i in range(pos):
    print(i+1)

for i in reversed(range(pos+1,n-1)):
    print(i+1)

print(pos+1)

Submission status: Accepted

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

check_min = 0
index_min = n

for i in range(n-1):
    if check_min < a[i] + a[i+1]:
        check_min = a[i] + a[i+1]
        index_min = i

if check_min < l:
    print('Impossible')
else:
    print('Possible')
    for i in range(index_min):
        print(i+1)
    for i in range(n-2, index_min, -1):
        print(i+1)
    print(index_min+1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l,*a=map(int,open(0).read().split())
ans=[]    
for i in range(1,n):
    if a[i]+a[i-1]<l:
        ans.append(i)
    else:
        for j in range(n-1,i-1,-1):
            ans.append(j)
        print("Possible")
        print(*ans,sep="\n")
        exit()
print("Impossible")

Submission status: Accepted

Solution code:
from collections import deque
N, L = map(int, input().split())
c = list(map(int, input().split()))
for i in range(len(c)-1):
  if c[i] + c[i+1] >= L:
    pos = i + 1
    break
else:
  print("Impossible")
  exit()

print("Possible")
for i in range(1,pos):
  print(i)
for i in range(len(c) -1, pos, -1):
  print(i)
print(pos)

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
a = list(map(int, input().split()))
ans = "Impossible"
last = 0

for i in range(n-1):
    A = a[i]+a[i+1]
    if A>=l:
        ans= "Possible"
        last = i+1
        break

if ans=="Impossible":
    print(ans)
else:
    print(ans)

    if last!=1:
        for i in range(last-1):
            print(i+1)

    if last!=n-1:
        for i in reversed(range(last+1,n)):
            print(i)

    print(last)

Submission status: Accepted

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

if not ll:
    print('Impossible')
else:
    print('Possible')
    for i in range(1,ll):
        print(i)
    for i in range(n-1,ll,-1):
        print(i)
    print(ll)

Submission status: Accepted

Solution code:
N,L,*A=map(int,open(0).read().split())
for i,a,b in zip(range(1,N),A,A[1:]):
    if a+b>=L:print("Possible",*range(1,i));print(*range(N-1,i-1,-1));quit()
print("Impossible")

Submission status: Accepted

Solution code:
def resolve():
    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(i):
                print(j + 1)
            for j in range(n - 1, i, -1):
                print(j)
            return 0
    print("Impossible")


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

#(方針)ロープの和がある2か所でL以上ならPossible,それ以外ならImposible
#→Possibleな理由はその2か所以外から1つずつほどいていけば必ずL以上の部分ができるから
#→端からほどくとわかりやすい(?)
#→両端から行かないとL以上の部分が存在しなくなることがある

judge = 0
p1,p2 = -1,-1 #2か所で和がL以上になるところ
for i in range(N):
  if(i != N-1):
    if(A[i]+A[i+1] >= L):
      judge = 1
      p1,p2 = i,i+1
      break
point = p1+1 #p1とp2の結び目(index→問題文の数)

if(judge == 0): print('Impossible')
else:
 print('Possible')
 for i in range(1,N):
  if(i == point): break
  else: print(i)
 for i in range(1,N):
  j = N-i
  if(j == point): break
  else: print(j) 
 print(point)

Submission status: Accepted

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

Submission status: Accepted

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

B = [A[i-1] + A[i] for i in range(1,N)]

if max(B) < L :
    print("Impossible")
else :
    print("Possible")

    ind = B.index(max(B))
    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 = 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(i):
            print(j+1)
        for j in range(N-1,i,-1):
            print(j)
        sys.exit()
print("Impossible")

Submission status: Accepted

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

flag = False
for i in range(n-1):
    if a[i] + a[i+1] >= l:
        flag = True
        pos = i
if flag:
    print('Possible')
    for i in range(n-1):
        if i < pos:
            print(i+1)
        elif i == pos :
            break
    for i in range(n-2, -1, -1):
        if i > pos :
            print(i+1)
        elif i == pos :
            break
    print(pos+1)
else:
    print('Impossible')


#%%

Submission status: Accepted

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

sum = [0]*(N - 1)
for i in range(N-1):
    sum[i] = a[i] + a[i+1]

if max(sum) < L:
    print("Impossible")
else:
    print("Possible")
    id = sum.index(max(sum))
    for i in range(id):
        print(i+1)
    for i in reversed(range(id+1, N-1)):
        print(i+1)
    print(id+1)

Submission status: Accepted

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


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

    # KeyInsight
    # 最後から直前の状態を考える
    # ある位置a[i]と右隣の値a[i+1]の和がL以上であれば構成できる
    # iの位置を特定
    # 左右の両端から切る
    pos = -1

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

    if pos == -1:
        print("Impossible")
    else:
        print("Possible")

        # 1-indexに
        pos += 1

        # See:
        # https://atcoder.jp/contests/agc002/submissions/7179969
        ans = [i for i in range(1, pos)] + [i for i in range(n - 1, pos, -1)] + [pos]
        print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()

Submission status: Accepted

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


for n in range(N - 1):
    if A[n] + A[n + 1] >= L:
        print('Possible')
        tmp_ind = n + 1
        for m in range(1, tmp_ind):
            print(m)
        for m in range(N - 1, tmp_ind, -1):
            print(m)
        print(tmp_ind)
        sys.exit()
print('Impossible')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,L=map(int,input().split())
l=list(map(int,input().split()))
judge="Impossible"
index=0

for i in range(N-1):
    if (l[i]+l[i+1])>=L:
        judge="Possible"
        index=i
        break

print(judge)
if judge=="Impossible":
    exit()

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

for i in range(index+2,N)[::-1]:
    print(i)

print(index+1)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

# 結び目のリストを作っておく
B = []
for i in range(1, N):
    B.append(A[i-1]+A[i])
mx = max(B)
# 一番長いところがL未満なら無理
if mx < L:
    print('Impossible')
    exit()

# 一番長いところに集めてくるように切る
print('Possible')
idx = B.index(mx)
for i in range(idx):
    print(i+1)
for i in range(N-2, idx, -1):
    print(i+1)
print(idx+1)

Submission status: Accepted

Solution code:
# AGC002C - Knot Puzzle
def main():
    N, L, *A = map(int, open(0).read().split())
    B = [i + j for i, j in zip(A, A[1:])]
    x = max(B)
    if x < L:  # corner case
        print("Impossible")
        return
    idx = B.index(x) + 1
    # keep the biggest one until the end
    ans = [i for i in range(1, idx)] + [i for i in range(N - 1, idx, -1)] + [idx]
    print("Possible")
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC002C - Knot Puzzle
def main():
    N, L, *A = map(int, open(0).read().split())
    B = [i + j for i, j in zip(A, A[1:])]
    x = max(B)
    if x >= L:  # at least one pair must be equal or greater than L
        idx = B.index(x) + 1
        # keep the biggest one until the end
        ans = [i for i in range(1, idx)] + [i for i in range(N - 1, idx, -1)] + [idx]
        print("Possible")
        print("\n".join(map(str, ans)))
    else:
        print("Impossible")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 2019/09/18

n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=[]
res=[]
last=0

flag=False
for i in range(n-1):
    if flag:
        res.append(i+1)
        continue
    if a[i]+a[i+1]<k:
        ans.append(i+1)
    elif not flag:
        last=i
        flag=True

if not flag:
    print('Impossible')
    exit()
if res:
    for e in res[::-1]:
        ans.append(e)
ans.append(last+1)

print('Possible')
print(*ans,sep='\n')

Submission status: Accepted

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')

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

print(ans_index)

Submission status: Accepted

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

Solution code:
N, L = map(int, input().split())
As = list(map(int, input().split()))
n = -1
for i in range(1, N):
  if As[i-1]+As[i] >= L:
    n = i
    break
#print(n)
if n < 0:
  print("Impossible")
  exit()
print("Possible")
for i in range(n-1):
  print(i+1)
for i in reversed(range(n, N)):
  print(i)

Submission status: Accepted

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

aa_max=-1
aa_i=-1
for i in range(N-1):
  if a[i]+a[i+1]>aa_max:
    aa_max=a[i]+a[i+1]
    aa_i=i
#print(aa_max,aa_i)

if aa_max<L:
  print("Impossible")
else:
  print("Possible")
  for i in range(aa_i):
    print(i+1)
  for i in range(N-2,aa_i-1,-1):
    print(i+1)

Submission status: Accepted

Solution code:
import sys,bisect,heapq

mod = 10**9+7
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(input())
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while(a%b != 0):
        a,b = b,a%b
    return b

def LCM(a,b):
    return a*b//GCD(a,b)

def main():
    N,L = LI()
    A = LI()
    ans = "Impossible"

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

    if ans == "Impossible":
        print(ans)
    else:
        print(ans)
        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 = [int(i) for i in input().split()]

max_k = 0
max_p = 0

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

if max_k < L:
    print('Impossible')
    exit()
else:
    print('Possible')

for i in range(1, N):
    if i == max_p:
        break
    else:
        print(i)

for i in range(N-1, 0, -1):
    if i == max_p:
        print(i)
        exit()
    else:
        print(i)

Submission status: Accepted

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

def equal_or_over_idx():
    for i in range(N-1):
        if a_list[i]+a_list[i+1] >=L:
            return i
    return -1

idx = equal_or_over_idx()
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:
#!/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')
for i in range(1,inde):
  print(i)
for i in range(inde+1,n)[::-1]:
  print(i)
print(inde)

Submission status: Accepted

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()
for i in range(1,n):
    if a[i] + a[i-1] >= l:
        print('Possible')
        for j in range(1,i):
            print(j)
        for k in range(i+1,n)[::-1]:
            print(k)
        print(i)
        break
else:
    print('Impossible')

Submission status: Accepted

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):
    print(i+1)
  for i in range(tiepoint+1,n-1)[::-1]:
      print(i+1)
  print(tiepoint+1)
else:print("Impossible")

Submission status: Accepted

Solution code:

n, l = [ int(v) for v in input().split() ]
knot_list = [ int(v) for v in input().split() ]

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

Submission status: Accepted

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(N-2, i, -1)]+[i+1]), sep='\n')
        break
else:
    print('Impossible')

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():
    n,m = LI()
    f = [1]*n
    l = [0]*n
    l[0] = 1
    for i in range(m):
        x,y = LI()
        x -= 1
        y -= 1
        if l[x]:
            l[y] = 1
        f[x] -= 1
        f[y] += 1
        if f[x] == 0:
            l[x] = 0
    ans = 0
    for i in range(n):
        if l[i]:
            ans += 1
    print(ans)
    return

#C
def C():
    n,l = LI()
    a = LI()
    for i in range(n-1):
        if a[i]+a[i+1] >= l:
            break
    else:
        print("Impossible")
        return
    ans = list(range(1,i+1))+list(range(i+2,n))[::-1]+[i+1]
    print("Possible")
    for i in ans:
        print(i)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

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(n-1,i,-1):
            print(k)
        exit()
print("Impossible")

Submission status: Accepted

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]))[::-1]
    for i in an[::-1]:
        print(i)

Submission status: Accepted

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(N - 1, i, -1))
        ans += list(range(1, i + 1))
    else:
        ans += list(range(1, i + 1))
    print(*ans, sep='\n')
else:
    print('Impossible')

Submission status: Accepted

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()))
    for i in range(1, n):
        if a[i] + a[i-1] >= l:
            print("Possible")
            for j in range(n-1, i, -1):
                print(j)
            for j in range(1, i):
                print(j)
            print(i)
            exit()
    print("Impossible")


if __name__ == '__main__':
    slove()

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')
    r=list(range(1,x+1))+list(range(N-1,x+1,-1))+[x+1,]
    print(*r,sep='\n')

Submission status: Accepted

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

last = -1
for i in range(N-1):
    if a[i] + a[i+1] >= L:
        last = i
        break
if last == -1:
    print('Impossible')
    sys.exit()

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

Submission status: Accepted

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,cur):
        print(i)
    for i in range(n-1,cur,-1):
        print(i)
    print(cur)
else:
    print('Impossible')