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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
逆再生。長さL以上になるものをくっつけられる。
一度L以上になったらそこだけ見ていけばよい
"""

N,L = map(int,input().split())
A = [int(x) for x in input().split()]

A2 = [x+y for x,y in zip(A,A[1:])]

M = max(A2)
i = A2.index(M)
if M < L:
    answer = ['Impossible']
else:
    answer = ['Possible']
    i += 1 # ここを最後にする
    answer += [str(x) for x in range(1,i)] + [str(x) for x in range(N-1,i,-1)] + [str(i)]

print('\n'.join(answer))

Submission status: Accepted

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

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

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

else:
    print("Impossible")

Submission status: 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()))
    s = sum(a)
    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")


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N, L, *A = map(int, open(0).read().split())

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

if k == -1:
    print("Impossible")
else:
    print("Possible")
    for j in range(1, k):
        print(j)
    for j in reversed(range(k + 1, N)):
        print(j)
    print(k)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC002C - Knot Puzzle
def main():
    N, L = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    B = [i + j for i, j in zip(A, A[1:])]
    x = max(B)
    if x >= L:
        idx = B.index(x) + 1
        ans = [i for i in range(1, idx)] 
        ans += [i for i in range(N - 1, idx, -1)] + [idx]
        print("Possible")
        print(*ans, sep="\n")
    else:
        print("Impossible")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

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

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

    for i in range(left):
        print(i + 1)
    for j in range(left, N - 1)[:: -1]:
        print(j + 1)


sol()

Submission status: Accepted

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

A2 = [x+A[ind+1] for ind,x in enumerate(A[:-1])]
A2.index(max(A2))
if(max(A2)<L):
    print('Impossible')
else:
    print('Possible')
    last = A2.index(max(A2))
    for i in range(last):
        print(i+1)
    for i in range(N-1,last+1,-1):
        print(i)
    print(last+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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+1
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

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

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

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

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

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

Submission status: 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,-1):
    print(i+1)

Submission status: Accepted

Solution code:
N, L = [int(_) for _ in raw_input().split(" ")]
ret =  [int(_) for _ in raw_input().split(" ")]
index = 0
for i in range(1, len(ret)):
  s = ret[i] + ret[i-1]
  if  L <= s:
    index = i+1
    break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(1, N):
        if A[i-1] + A[i] >= L:
            print("Possible")
            for j in range(1, i):
                print(j)
            for j in range(N-1, i-1, -1):
                print(j)
            return
    print("Impossible")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def get_ints():
    return list(map(int, input().split()))

[n, l] = get_ints()
a = get_ints()

for i in range(n - 1):
    if a[i] + a[i + 1] < l:
        continue
    print("Possible")
    for j in range(1, i + 1):
        print(j)
    for j in range(n - 1, i, -1):
        print(j)
    exit(0)

print("Impossible")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

piv = -1
b_s = []
for i in range(n - 1):
  a2 = a_s[i] + a_s[i + 1]
  b_s.append(a2)
  if a2 >= l:
    piv = i

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    global N, L
    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:
            return i+1
    return False
ans = solve()
if ans:
    print('Possible')
    for i in range(1, ans):
        print(i)
    for i in range(N-1, ans, -1):
        print(i)
    print(ans)
else:
    print("Impossible")

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
a = list(map(int,input().split()))
for N in range(n - 1):
    a[N] = a[N] + a[N + 1]
if max(a) >= l:
    print('Possible')
    ind = a.index(max(a)) + 1
    for  i in range(ind - 1):
        print(i + 1)
    for i in range(n - ind):
        print(n - i - 1)
else:
    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
        idx=i+1
        break
if not flag:
    print('Impossible')
else:
    print('Possible')
    for i in range(1,idx):
        print(i)
    for i in range(N-1,idx,-1):
        print(i)
    print(idx)

Submission status: Accepted

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

YES = "Possible"  # type: str
NO = "Impossible"  # type: str

def solve(N: int, L: int, a: "List[int]"):
    pair_length = [a[i] + a[i+1] for i in range(N-1)]
    longest_pair = max(pair_length)
    
    if longest_pair < L:
        print(NO)
        return
    
    print(YES)
    last_knot = pair_length.index(longest_pair)
    for i in range(last_knot):
        print(i+1)
    for i in range(N-2, last_knot-1, -1):
        print(i+1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, L, a)

if __name__ == '__main__':
    main()

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)
        break
else:
    print("Impossible")

Submission status: Accepted

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

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

a_list = []
for i in range(N-1):
    a_list.append([a[i]+a[i+1],i])
    
a_list=sorted(a_list,key=lambda x:x[0],reverse=True)

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

Submission status: Accepted

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

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

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


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

Submission status: Accepted

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

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

if not is_possible:
  print('Impossible')
else:
  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)

Submission status: Accepted

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

I = [i + 1 for i in range(N - 1) if a[i] + a[i + 1] >= L]
ans = (
    'Possible\n{}'.format(
        '\n'.join(
            map(
                str,
                list(range(1, I[0])) + list(range(N - 1, I[0], -1)) + [I[0]]
            )
        )
    ) if I else
    'Impossible'
)

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")
    break
else:
  print("Impossible")
  exit()
li = list(range(1,i+1))+list(range(n-1,i+1,-1))+[i+1]
for x in li:
  print(x)

Submission status: Accepted

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

Submission status: Accepted

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

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


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, L] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]
    B = deque([A[i] + A[i + 1] for i in range(N - 1)])
    sumA = sum(A)
    s_idx = 1
    t_idx = len(B)
    seq = []
    for i in range(N - 1):
        if sumA < L:
            print "Impossible"
            return
        if B[len(B) - 1] < L:
            B.pop()
            sumA -= A[t_idx]
            seq.append(t_idx)
            t_idx -= 1

        else :
            B.popleft()
            sumA -= A[s_idx - 1]
            seq.append(s_idx)
            s_idx += 1
        if len(seq) == N - 1:
            break

    print "Possible"
    for i in range(len(seq)):
        print seq[i]





if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, l = LI()
    A = LI()

    for i in range(n - 1):
        if A[i] + A[i + 1] >= l:
            k = i
            print('Possible')
            break
    else:
        print('Impossible')
        return 0

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

    for i in range(k, n - 1)[::-1]:
        print(i + 1)

    return 1


main()

Submission status: Accepted

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

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

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

print("Possible")

for i in range(1,last_undo):
  print(i)
for i in range(last_undo+1,n)[::-1]:
  print(i)
print(last_undo)

Submission status: Accepted

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


X = [A[i] + A[i + 1] for i in range(N - 1)]
if any(map(lambda x: x >= L, X)):
    print('Possible')

    for i, x in enumerate(X, start=1):
        if x >= L:
            xi = i
            break

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

else:
    print('Impossible')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
inf = float("inf")

n,L = map(int,input().split())
a = tuple(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 sys
N,L=map(int,input().split())
A=[int(i) for i in input().split()]
s=10**23
for i in range(N-1):
    if A[i]+A[i+1]>=L:
        s=i
        break
if s==10**23:
    print('Impossible')
    sys.exit()
print('Possible')
L=[]
for i in range(s):
    L.append(i+1)
for i in range(N-2,s,-1):
    L.append(i+1)
L.append(s+1)
#print(L,s)
print('\n'.join(map(str,L)))

Submission status: Accepted

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

if index == -1:
    print("Impossible")
else:
    print("Possible")
    i = 1
    while i < index:
        print(i)
        i += 1
    i = N - 1
    while index - 1 < i:
        print(i)
        i -= 1

Submission status: Accepted

Solution code:
n,l = (int(i) for i in input().split())
a = list(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,i+2,-1):
      print(j-1)
    for k in range(1,i+2):
      print(k)
    exit()
print('Impossible')

Submission status: Accepted

Solution code:
N, L = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
P = "Possible"
for i in range(N-1):
  if a[i] + a[i+1] >= L:
    start = i
    break  
else:
  P = "Impossible"
print(P)

if P == "Possible":
  ans = [start]
  if start > 0:
    ans += reversed(list(range(start)))
  if start != N-2:
    ans += list(range(start+1, N-1))
  ans.reverse()
  for a in ans:
    print(a+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
*a,=map(int,input().split())
v=[0]

for i in range(n-1):
  if a[i]+a[i+1]>=l:
    v[0]=i+1
    v+=list(range(1,i+1)[::-1])
    v+=list(range(i+2,n))
    print("Possible")
    print(*v[::-1],sep="\n")
    break
else:
  print("Impossible")

Submission status: Accepted

Solution code:
from itertools import accumulate as ac

n,l=map(int,input().split())
*a,=map(int,input().split())
v=[]

for i in range(n-1):
  if a[i]+a[i+1]>=l:
    v.append(i+1)
    break
else:
  print("Impossible")

if v:
  st=v[0]
  v+=list(range(1,st)[::-1])
  v+=list(range(st+1,n))
  print("Possible")
  for i in v[::-1]:
    print(i)

Submission status: Accepted

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

CanRemain = []
CutFirst = []
for i in range(N-1):
    if A[i] + A[i+1] >= L: CanRemain.append(i+1)
    else: CutFirst.append(i+1)

if not CanRemain: print("Impossible")
else:
    print("Possible")
    for num in CutFirst:
        if num < CanRemain[-1]: print(num)
        else: break
    for i in reversed(range(len(CutFirst))):
        if CutFirst[i] > CanRemain[-1]: print(CutFirst[i])
        else: break
    for num in CanRemain: print(num)

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
l = map(int, raw_input().split())
ind = -1
for i in range(n - 1):
	if l[i] + l[i + 1] >= k:
		ind = i
		break
if ind == -1:
	print "Impossible"
else:
	print "Possible"
	for i in range(1, ind + 1):
		print i 
	for i in range(n - 1, ind, -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,len(a)):
    if a[i]+a[i-1]<L:
        pass
    else:
        print("Possible")
        for j in range(1,i):
            print(j)
        for k in range(len(a)-i-1):
            print(len(a)-1-k)
        print(i)
        exit()
print("Impossible")

Submission status: Accepted

Solution code:
import sys
N,L=map(int,input().split())
A=[int(i) for i in input().split()]
flag=True
a=-1
for i in range(N-1):
    if A[i+1]+A[i]>=L:
        flag=False
        a=i+1
        break
if flag:
    print('Impossible')
    sys.exit()
print('Possible')
for i in range(1,a):
    print(i)
for i in range(N-1,a,-1):
    print(i)
print(a)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
a=[int(i) for i in input().split()]
Longest_pair=0
p=0
for i in range(N-1):
  if a[i]+a[i+1]>Longest_pair:
    Longest_pair=a[i]+a[i+1]
    p=i+1
if Longest_pair<L:
  print("Impossible")
  exit()
else:
  print("Possible")
for i in range(1,p):
  print(i)
for i in range(p+1,N)[::-1]:
  print(i)
print(p)

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
import sys
N, L = inpl()
a = inpl()
b = []
for i in range(N-1):
    b.append(a[i]+a[i+1])
bmax = max(b)
if bmax < L:
    print('Impossible')
    sys.exit()

print('Possible')
ans = b.index(bmax)

Ans = list(range(0,ans)) + list(range(N-2,ans,-1))+[ans]
for i in range(N-1):
    print(Ans[i]+1)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
a=[int(i) for i 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("Possible")
    for i in range(j):
        print(i+1)
    for i in range(j+1,N-1)[::-1]:
        print(i+1)
    print(j+1)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,l = li()
a = list(li())

exist = False

for i, (ap, an) in enumerate(zip(a[:-1], a[1:])):
    if ap + an >= l:
        bef = [j+1 for j in range(i)]
        aft = [j+1 for j in range(n-2,i,-1)]
        ans = bef + aft + [i+1]
        exist = True
        break

if exist:
    print("Possible")
    for ai in ans:
        print(ai)

else:
    print("Impossible")

Submission status: Accepted

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

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

Submission status: Accepted

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

atom = -1
for i in range(n-1):
    if l <= a[i] + a[i+1]:
        atom = i
        break
        
if atom < 0:
    print('Impossible')
else:
    print('Possible')
    for i in range(atom):
        print(i+1)
    for i in range(n-atom-1):
        print(n-1-i)

Submission status: Accepted

Solution code:
ai = lambda: list(map(int, input().split()))

n,l = ai()
a = ai()

f = 0
for i in range(1,n):
    if a[i-1]+a[i] >= l:
        f = 1
        key = i
        break
if f:
    print('Possible')
    b = list(range(n))
    c = b[1:key]
    c += b[-1:key:-1]
    c += [key]
    print(*c, sep='\n')
else:
    print('Impossible')

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a = [int(x) for x in input().split()]
for i in range(1,n):
    if a[i-1] +a[i]>= 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")