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()))
start = 0
end = len(a) - 1
r = []
flag = True

while start < end:
	if (end - start) == 1:
		if (a[start] + a[end]) < l:
			flag = False
	if a[0] < a[-1]:
		r.append(start+1)
		start += 1
	else:
		r.append(end)
		end -= 1

if flag:
	print('Possible')
	for rr in r:
		print(rr)
else:
	print('Impossible')

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
a = list(map(int, input().split()))
S = sum(a)
ans = []
f = 0
l = len(a)-1

if l-f==1:
    if S<L:
        print("Impossible")
        exit()
    else:
        print("Possible")
        print(1)
        exit()

while l-f>1:
    if S-a[f]<L and S-a[l]<L:
        print("Impossible")
        exit()
    elif a[f]<a[l]:
        S -= a[f]
        ans.append(f+1)
        f += 1
    else:
        S -= a[l]
        ans.append(l)
        l -= 1
ans.append(l)

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

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
a = list(map(int, input().split()))
start = 0
end = len(a) - 1
r = []
flag = True

while start < end:
	if (end - start) == 1:
		print(a[start], a[end])
		if (a[start] + a[end]) < l:
			flag = False
	if a[0] < a[-1]:
		r.append(start+1)
		start += 1
	else:
		r.append(end)
		end -= 1

if flag:
	print('Possible')
	for rr in r:
		print(rr)
else:
	print('Impossible')

Submission status: Wrong Answer

Solution code:
N, M = map(int, raw_input().split(" "))
a = map(int, raw_input().split(" "))
ans = []
cut = [1, len(a)-1]
for i in xrange(N):
    if a[0] < a[len(a)-1] and len(a) > 1:
        a.pop(0)
        ans.append(cut[0])
        cut[0] += 1
        if sum(a) < M:
            print "Impossible"
            break
    if a[0] > a[len(a)-1]:
        ans.append(cut[1])
        cut[1] -= 1
        a.pop()
        if sum(a) < M and len(a) > 1:
            print "Impossible"
            break
if len(ans) > 0:
    print "Possible"
else:
    print "Impossible"
for i in ans:
    print i

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
a = list(map(int, input().split()))
S = sum(a)
ans = []
f = 0
l = len(a)-1

if l-f==1:
    if S-a[f]<L and S-a[l]<L:
        print("Impossible")
        exit()
    else:
        print("Possible")
        print(1)
        exit()
        
while l-f>1:
    if S-a[f]<L and S-a[l]<L:
        print("Impossible")
        exit()
    elif a[f]<a[l]:
        S -= a[f]
        ans.append(f+1)
        f += 1
    else:
        S -= a[l]
        ans.append(l)
        l -= 1
ans.append(l)
print("Possible")
for x in ans:
    print(x)

Submission status: Wrong Answer

Solution code:
import sys

N, L = map(int, sys.stdin.readline().split())
As = map(int, sys.stdin.readline().split())

tot = sum(As)

res = []

a = 0
b = N-1
while b - a > 0:
    na = As[a]
    nb = As[b]

    if tot < L:
        print "Impossible"
        sys.exit()

    if na < nb:
        tot -= na
        res.append(a)
        a += 1
    else:
        tot -= nb
        res.append(b-1)
        b -= 1

print "Possible"
for a in res:
    print a+1

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
A = list(map(int, input().split()))
sum_A = sum(A)
ans = []
i = 0
j = len(A) - 1
while True:
    # print(i, j)
    if i == j:
        print("Possible")
        for an in ans:
            print(an)
        break
    if sum_A < L:
        print("Impossible")
        break
    if A[i] < A[j]:
        sum_A -= A[i]
        ans.append(i + 1)
        i += 1
    else:
        sum_A -= A[j]
        ans.append(j)
        j -= 1

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, L = map(int, raw_input().split())
a = map(int, raw_input().split())

mx, idx = 0, 0
for i, ai in enumerate(a):
    if ai > mx:
        mx = ai
        idx = i

if a[idx] >= L:
    print "Possible"
    for i in xrange(idx):
        print i + 1
    for i in xrange(N - 1, idx, -1):
        print i
else:
    if idx > 0:
        if a[idx] + a[idx - 1] >= L:
            print "Possible"
            for i in xrange(idx - 1):
                print i + 1
            for i in xrange(N - 1, idx, -1):
                print i
            print idx + 1
            exit()
    if idx < N - 1:
        if a[idx] + a[idx + 1] >= L:
            print "Possible"
            for i in xrange(idx):
                print i + 1
            for i in xrange(N - 1, idx + 1, -1):
                print i
            print idx + 1
            exit()
    print "Impossible"

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, L = map(int, raw_input().split())
a = map(int, raw_input().split())

mx, idx = 0, 0
for i, ai in enumerate(a):
    if ai > mx:
        mx = ai
        idx = i

if a[idx] >= L:
    print "Possible"
    for i in xrange(idx):
        print i + 1
    for i in xrange(N - 1, idx, -1):
        print i
else:
    if idx > 0:
        if a[idx] + a[idx -1] >= L:
            print "Possible"
            for i in xrange(idx - 1):
                print i + 1
            for i in xrange(N - 1, idx, -1):
                print i
            print idx
            exit()
    if idx < N - 1:
        if a[idx] + a[idx + 1] >= L:
            print "Possible"
            for i in xrange(idx):
                print i + 1
            for i in xrange(N - 1, idx + 1, -1):
                print i
            print idx + 1
            exit()
    print "Impossible"

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def solve():
    N,L = map(int,input().split())
    As = list(map(int,input().split()))
    for i in range(N-1):
        if As[i] + As[i+1] >= L:
            print("Possible")
            keep = i + 1
            for n in range(1,N):
                if n != keep:
                    print(n)
            print(keep)
            return
    print("Impossible")
        
solve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# a = int(input())
# b, c
# s = input()


yes = "Possible"
no = "Impossible"

N, L = map(int, input().split())
a = [0] + list(map(int, input().split()))

c = 0
Mi = -1
for i in range(1, N):
	if c < a[i] + a[i+1]:
		c = max(c, a[i] + a[i+1])
		Mi = i

if c < L:
	print(no)
else:
	print(yes)
	for i in range(1, N):
		if i != Mi:
			print(i)
	print(Mi)

Submission status: Time Limit Exceeded

Solution code:
N, L = map(int, input().split())
A = list(map(int, input().split()))
d = [A[i] + A[i+1] for i in range(N-1)]
if max(d) < L:
  print("Impossible")
else:
  print("Possible")
  j = 0
  while d[j] != max(d):
    j += 1
  for i in range(j):
    print(i+1)
  for i in range(j, N-1):
    print(N-i+j-1)

Submission status: Time Limit Exceeded

Solution code:
N, L = map(int, input().split())
A = list(map(int, input().split()))
b = [0] * (N - 1)
c = [N - 1]
l, r = -1, N - 1
imp = 1
for i in range(N - 1):
    if A[i] + A[i + 1] >= L:
        imp = 0


def func(x):
    if b[x] == 0:
        l = A[x] + A[x + 1]
        if l >= L:
            b[x] = c[0]
            c[0] -= 1
            A[x], A[x + 1] = l, l
            return 1
    return 0


if not imp:
    while (c[0] > 0):
        cf = c[0]
        mid = (r + l) // 2
        if func(mid):
            r = mid
        else:
            l = mid
        if r - l < 1:
            l, r = 0, N - 1


if imp:
    print('Impossible')
else:
    print('Possible')
    for ans in b:
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, L = map(int, input().split())
A = list(map(int, input().split()))
nl = set(range(N - 1))
b = [0] * (N - 1)
c = N - 1
imp = 0
while (c > 0):
    cf = c
    for i in nl:
        if b[i] == 0:
            l = A[i] + A[i + 1]
            if l >= L:
                b[i] = c
                c -= 1
                A[i], A[i + 1] = l, l
    if cf == c:
        imp = 1
        break
if imp:
    print('Impossible')
else:
    print('Possible')
    for ans in b:
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, L = map(int, input().split())
A = list(map(int, input().split()))
b = [0] * (N - 1)
c = N - 1
imp = 0
while (c > 0):
    cf = c
    for i in range(N - 1):
        if b[i] == 0:
            l = A[i] + A[i + 1]
            if l >= L:
                b[i] = c
                c -= 1
                A[i], A[i + 1] = l, l
    if cf == c:
        imp = 1
        break
if imp:
    print('Impossible')
else:
    print('Possible')
    for ans in b:
        print(ans)

Submission status: Time Limit Exceeded

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

ans = []
seen = [0] * (n - 1)
while True:
    changed = False
    for i in range(n - 1):
        if not seen[i] and a[i] + a[i + 1] >= l:
            seen[i] = 1
            ans.append(i + 1)
            a[i] = l
            a[i + 1] = l
            changed = True
    if not changed:
        break

if len(ans) == n - 1:
    print("Possible")
    print(*ans[::-1], sep="\n")
else:
    print("Impossible")

Submission status: Time Limit Exceeded

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))
    res.append(idx)
else:
    print("Possible")
    for r in res: print(r)

Submission status: Time Limit Exceeded

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

def main():
    N, L = map(int, input().split())
    A = list(map(int, input().split()))
    a, b = 1, N-1
    l = []
    la = N
    for i in range(N-1):
        if A[i] + A[i+1] >= L:
            la = i
            break
    if la == N:
        print('Impossible')
        return
    while len(A) > 2:
        if a-1 != la:
            l += [a]
            a += 1
            A = A[1:]
        else:
            l += [b]
            b -= 1
            A = A[:-1]
    print('Possible')
    l+=[la+1]
    for i in l : print(i)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
knots = []
n, l = map(int, raw_input().split())
a = map(int, raw_input().split())
index = range(0,n+1)
# print a
while len(knots) < n-1:
    i = 0
    untied = False
    while i < (len(a)-1):
        if a[i] + a[i+1] >= l:
            untied = True
            a[i] += a.pop(i+1)
            # print a
            # print "i", index
            knots.append(index[i+1])
            del index[i+1]
        i += 1
    if untied == False:
        print "Impossible"
        exit()
print "Possible"
for k in reversed(knots):
    print k

Submission status: Time Limit Exceeded

Solution code:
n, l = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
dp = [[None] * n for _ in range(n)]

Aacc = [A[0]]
for i in range(1, n):
    Aacc.append(Aacc[i - 1] + A[i])

def length(a, b):
    return Aacc[b] - (Aacc[a - 1] if a > 0 else 0)

def search(a, b):
    if dp[a][b] is None:
        if a == b:
            ans = []
        elif length(a, b) >= l:
            for cut in range(a, b):
                left = search(a, cut)
                if left is not False:
                    right = search(cut + 1, b)
                    if right is not False:
                        ans = [cut] + left + right
                        break
            else:
                ans = False
        else:
            ans = False

        dp[a][b] = ans

    return dp[a][b]

ans = search(0, n - 1)
if ans is False:
    print('Impossible')
else:
    print('Possible')
    for a in ans:
        print(a + 1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

n, length = list(map(int, input().split()))
nums = list(map(int, input().split()))

idx = -1
for i in range(n-1):
    if nums[i] + nums[i+1] >= length:
        idx = i
        break
if idx < 0:
    print('Impossible')
    exit()

print('Possible')
for i in range(idx):
    print(i+1)
for i in reversed(range(idx, n-1)):
    print(i+1)

Submission status: Accepted

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

f = 0
for i in range(N-1):
    if a[i] + a[i+1] >= L:
        f = 1
        t = i
        break
#print(t)
if f == 0:
    print("Impossible")
else:
    print("Possible")
    ans = []
    for i in range(t):
        ans.append(i+1)
    for i in range(N-1, t, -1):
        ans.append(i)
    #print(ans)
    for x in ans:
        print(str(x))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

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

N, L = getNM()
A = getList()
max_len_knot, max_len = -1, 0
for i in range(N - 1):
    if A[i] + A[i + 1] > max_len:
        max_len_knot = i
        max_len = A[i] + A[i + 1]
if max_len < L:
    print('Impossible')
else:
    print('Possible')
    for i in range(max_len_knot):
        print(i + 1)
    for i in range(N - 2, max_len_knot, -1):
        print(i + 1)
    print(max_len_knot + 1)

Submission status: Accepted

Solution code:
N,L=list(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')
    k=i
    break
else:
  print('Impossible')
  exit()
ans=[0]*(N-1)
ans[k]=N-1
for i in range(k):
  ans[i]=i+1
for i in range(N-2-k):
  ans[N-i-2]=k+i+1
for i in range(N-1):
  print(ans[i])

Submission status: Accepted

Solution code:
def main():
    N, L = list(map(int, input().split()))
    A = list(map(int, input().split()))
    max_len_knot, max_len = - 1, 0
    for i in range(N - 1):
        if A[i] + A[i + 1] > max_len:
            max_len_knot = i
            max_len = A[i] + A[i + 1]
    if max_len < L:
        print('Impossible')
    else:
        print('Possible')
        for i in range(max_len_knot):
            print(i + 1)
        for i in range(N - 2, max_len_knot, -1):
            print(i + 1)
        print(max_len_knot + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

i = 0

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = list(map(int, input().split()))
k = -1
for i in range(N-1):
    if A[i]+A[i+1]>=L:
        k=i+1
if k==-1:
    print("Impossible")
else:
    print("Possible")
    res = []
    for i in reversed(range(1,k+1)):
        res.append(i)
    for i in range(k+1,N):
        res.append(i)
    for i in reversed(res):
        print(i)

Submission status: Accepted

Solution code:
def solve(A,L):
    N = len(A)
    for i in range(N-1):
        if A[i]+A[i+1] >= L:
            pro = i
            break
    else:
        return None

    res = list(range(i))+list(reversed(range(i+1,N-1)))+[i]
    return res


if __name__ == '__main__':
    N,L = map(int,input().split())

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

    res = solve(A,L)
    if res is None:
        print('Impossible')
    else:
        print('Possible')
        print(*(v+1 for v in res), sep='\n')

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

"""
逆順に見る，2つで長さL以上のものが作れればOKそうでなければ不可

最初dequeで解こうとしたけど，純粋に間違ってた
"""
def main():
    mod=10**9+7
    N,L=MI()
    A=LI()
    t=-1 #最後に外すとこ
    for i in range(N-1):
        # 結び目iを見る
        temp=A[i]+A[i+1]
        if temp >= L:
            t=i
            break
        
    if t==-1:
        print("Impossible")
    else:
        print("Possible")
        ans=[]
        for i in range(t):
            ans.append(i)
        for i in range(N-2,t,-1):
            ans.append(i)
        ans.append(t)
        
        for i in ans:
            print(i+1)
            
    
    
    

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N, L = in_nn()
    A = in_nl()

    max_l = 0
    ind = -1
    for i in range(N - 1):
        t = A[i] + A[i + 1]
        if max_l < t:
            ind = i
            max_l = t

    if max_l >= L:
        print("Possible")
        for i in range(1, ind + 1):
            print(i)
        for i in range(N - 1, ind, -1):
            print(i)
    else:
        print("Impossible")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,l = map(int,readline().split())
lst1 = list(map(int,readline().split()))

res = -1

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

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

ans = []
for i in range(res):
    ans.append(i)
for j in range(n-2,res,-1):
    ans.append(j)
ans.append(res)

for i in ans:
    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=[i+1]+list(range(i,0,-1))+list(range(i+2,n))
    print(*ans[::-1],sep='\n')
    break
else:print('Impossible')

Submission status: Accepted

Solution code:
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:
        print('Possible')
        print(*(list(range(1,i+1))+list(range(n-1,i+1,-1))),sep='\n')
        print(i+1)
        exit()
print('Impossible')

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
idx = -1
for i in range(n-1):
    if a[i]+a[i+1]>=k:
        idx = i
        break
if idx == -1:
    print('Impossible')
    exit()
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:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n, l = na()
    a = na()

    max_point = -1
    max_idx = -1
    for i in range(1, n):
        tmp = a[i] + a[i - 1]
        if tmp >= l:
            max_point = max(max_point, tmp)
            max_idx = i - 1

    if max_point == -1:
        print("Impossible")
        exit(0)

    tmp = [i for i in range(n - 1)]

    ans = []
    x = tmp[:max_idx]
    y = tmp[max_idx + 1:]
    y.reverse()

    ans = x + y

    print("Possible")
    for ansi in ans:
        print(ansi + 1)
    print(max_idx + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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 TUPLE(): return tuple(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 
#mod = 998244353
from decimal import *
import numpy as np
#decimal.getcontext().prec = 10

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

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

print("Possible")

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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 TUPLE(): return tuple(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 
#mod = 998244353
from decimal import *
import numpy as np
#decimal.getcontext().prec = 10

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

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

print("Possible")
ans = list(range(1, idx)) + list(range(N-1, idx, -1)) + [idx]
print(*ans, sep="\n")

Submission status: Accepted

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

count = 0
vouch = 0
A = []

for i in range (0, N-1):
	if count == 0:
		if L[i]+L[i+1] >= M:
			count=1
			A.append(N-1)
		else:
			A.append(i+1)
	else:
		A.append(N-2-vouch)
		vouch+=1

if count == 0:
	print('Impossible')
	exit()
else:
	print('Possible')
    
for i in range (0, N-1):
	print(A[i])

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
A = list(map(int,input().split()))
A.insert(0,0)
cmax = 0
ind = -1
for i in range(1,N):
    if A[i]+A[i+1]>cmax:
        cmax = A[i]+A[i+1]
        ind = i
if cmax>=L:
    print("Possible")
    for i in range(1,ind):
        print(i)
    for i in range(N-1,ind-1,-1):
        print(i)
else:
    print("Impossible")

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, L = mapint()
As = list(mapint())

procces = []
for i in range(1, N):
    double = As[i-1]+As[i]
    if double>=L:
        last = i
        print('Possible')
        break
else:
    print('Impossible')
    exit()
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()))

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

Submission status: Accepted

Solution code:
from collections import deque
def solve():
  ans = ['Possible']
  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:
      ind = i
      break
  else:
    return ['Impossible']
  for i in range(1,ind+1):
    ans.append(i)
  for i in range(N-1,ind+1,-1):
    ans.append(i)
  ans.append(ind+1)
  return ans
print(*solve(),sep='\n')

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = [start + 1]
for i in range(start + 1, N - 1):
    ans.append(i+1)
for i in reversed(range(start)):
    ans.append(i+1)

ans.reverse()
print("Possible")
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.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)
    break
else:
  print("Impossible")
  exit(0)
for i in range(res[0] - 1, -1, -1): res.append(i)
for i in range(res[0] + 1, N - 1): res.append(i)
res.reverse()
print("Possible")
for r in res: print(r + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, L = map(int, input().split())
    A = list(map(int, input().split()))

    init = -1
    for i in range(1, n):
        if A[i] + A[i - 1] >= L:
            init = i
            break
    else:
        print("Impossible")
        exit()
    res = []
    for i in range(1, init):
        res.append(i)

    for i in reversed(range(init + 1, n)):
        res.append(i)
    res.append(init)
    print("Possible")
    print(*res, sep="\n")


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n,l,*a=map(int,open(0).read().split())
i=0
for a,b in zip(a,a[1:]):i+=1;a+b>=l>exit(print('Possible',*range(1,i),*range(n-1,i-1,-1)))
print('Impossible')

Submission status: Accepted

Solution code:
n,l,*a=map(int,open(i:=0).read().split())
for a,b in zip(a,a[1:]):i+=1;a+b>=l>exit(print('Possible',*range(1,i),*range(n-1,i-1,-1)))
print('Impossible')