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:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, L = inpl()
A = inpl()

tmp = 0
connect = False
knot = None
for i in range(N):
    if A[i] >= L:
        knots = i
        break

if knot is None:
    for i in range(N - 1):
        if sum(A[i:i + 2]) >= L:
            knot = i
            connect = True
            break

if knot is None:
    print('Impossible')
else:
    print('Possible')
    for i in range(N - 1):
        if i == knot:
            break
        else:
            print(i + 1)

    for i in range(N - 2, -1, -1):
        if i == knot:
            break
        else:
            print(i + 1)
    if connect:
        print(knot + 1)

Submission status: Accepted

Solution code:
N, L, *a = map(int, open(0).read().split())
for i, (n, m) in enumerate(zip(a, a[1:]), 1):
    if n + m >= L:
        print('Possible')
        print('\n'.join(c for it in (range(1,i), range(N-1,i,-1), [i]) for c in map(str, it)))
        break
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()]
s,x,y,ans,num,z = sum(a),0,n-1,[],0,0
for i in range(n-1):
	num2 = a[i]+a[i+1]
	if num<num2: num,z = num2,i+1
if num>=l:
	print("Possible")
	for i in range(1,z): print(i)
	for i in range(n-1,z-1,-1): print(i)
else: print("Impossible")

Submission status: Accepted

Solution code:
def main22():
    strbuf = input("");
    strbufs = strbuf.split();
    buf = [];
    for i in range(2):
        buf.append(int(strbufs[i]));
    strbuf = input("");
    strbufs = strbuf.split();
    buf2 = [];
    for i in range(buf[0]):
        buf2.append(int(strbufs[i]));
    if buf[0] == 2:
        if buf2[0] + buf2[1] >= buf[1]:
            print("Possible");
            print(1);
        else:
            print("Impossible");
    else:
        point = -1;
        for i in range((buf[0] - 1)):
            if buf2[i] + buf2[i+1] >= buf[1]:
                point = i+1;
                break;
        if point == -1:
            print("Impossible");
        else:
            print("Possible");
            if point != 1:
                for i in range(point-1):
                    print(i+1);
            if point != buf[0] - 1:
                for i in range(buf[0]-1,point,-1):
                    print(i);
            print(point);

if __name__ == '__main__':
    main22()

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,L = inpl()
aa = inpl()
tmp = 0
for i in range(N-1):
	if aa[i] + aa[i+1] >= L:
		tmp += 1
		ind = i+1

if tmp == 0:
	print('Impossible')
else:
	print('Possible')
	for i in range(1,ind):
		print(i)
	for i in reversed(range(ind,N)):
		print(i)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, L, A):

    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 reversed(range(i+1, N-1)):
                print(j+1)
            print(i+1)
            return

    else:
        print('Impossible')


def main():
    N, L = read_int_n()
    A = read_int_n()
    slv(N, L, A)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for iKnot in range(1, N):
    if As[iKnot - 1] + As[iKnot] >= L:
        print('Possible')
        for i in range(1, iKnot):
            print(i)
        for i in reversed(range(iKnot + 1, N)):
            print(i)
        print(iKnot)
        break
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()]

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

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-1] + A[i] >= L:
        X = i
        break
else:
    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()))

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

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

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-1] + A[i] >= L:
        X = i
        break
else:
    print("Impossible")
    exit()

ans = []
for i in range(1, X):
    ans.append(i)
for i in range(N-1, X, -1):
    ans.append(i)
ans.append(X)
print("Possible")
print(*ans, sep="\n")

Submission status: Accepted

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

Submission status: Accepted

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

if n == 2:
	if a[0] + a[1] < l:
		print("Impossible")
	else:
		print("Possible")
		print(1)

else:
	nagai = 0
	for i in range(n - 1):
		if a[i] + a[i + 1] > nagai:
			nagai = a[i] + a[i + 1]
			nagai_index = i + 1

	if nagai < l:
		print("Impossible")
	else:
		print("Possible")
		for i in range(1, nagai_index):
			print(i)
		for i in range(n - 1, nagai_index, -1):
			print(i)
		print(nagai_index)

Submission status: Accepted

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

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

sums = [a[i]+a[i+1] for i in range(N-1)]

maxind, maxval = max(enumerate(sums), key=lambda x:x[1])
if maxval >= L:
    print("Possible")
    for i in range(maxind):
        print(i+1)
    for j in reversed(range(maxind, N-1)):
        print(j+1)
else:
    print("Impossible")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def cutSequence(piles, threshold):
    for i in xrange(len(piles)-1):
        if piles[i]+piles[i+1]>=threshold:
            return range(0, i)+range(len(piles)-2, i-1, -1)
    return []

def main():
    n, m = [int(x) for x in raw_input().strip().split()]
    a = [int(x) for x in raw_input().strip().split()]
    foo = cutSequence(a, m)
    if len(foo)==0:
        print 'Impossible'
    else:
        print 'Possible'
        for x in foo:
            print x+1

if __name__ == '__main__':
    main()

Submission status: Accepted

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

psbl=False
ans=0
for i in range(1,N):
  if A[i-1]+A[i]>=L:
    psbl=True
    ans=i-1
    break
if psbl==False:
  print("Impossible")
else:
  print("Possible")
  for i in range(ans):
    print(i+1)
  for j in range(N-1-ans):
    print(N-j-1)

Submission status: Accepted

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

for i,(a,b) in enumerate(zip(src, src[1:])):
    if a+b >= L:
        print('Possible')
        for j in range(1,i+1): print(j)
        for j in range(N-1,i,-1): print(j)
        exit()
print('Impossible')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def dump(n,k):
  for i in range(k-1):
    print(i+1)
  for i in range(n-1,k-1,-1):
    print(i)

n,l=map(int,input().split(' '))
a=input().split(' ')
a=[int(s) for s in a]

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

if k==0:
  print("Impossible")
else:
  print("Possible")
  dump(n,k)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N, L = map(int, input().split())
    a_list = list(map(int, input().split()))

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,L = list(map(int,input().split()))
a = list(map(int,input().split()))
a.append(0)
b = []
res = "Impossible"

for i in range(N):
    if L <= (a[i]+a[i+1]):
        count = i
        res = "Possible"
        break

if res =="Possible":
    for j in range(count):
        b.append(j+1)
    for k in range(count+1,N)[::-1]:
        b.append(k)
    
    print(res)
    for l in range(len(b)):
        print(b[l])
else:
    print(res)

Submission status: Accepted

Solution code:
temp=input().split()
N=int(temp[0])
L=int(temp[1])
a=[int(i) for i in input().split()]
flag=False
ans=[]

for i in range(N-1):
	if a[i]+a[i+1]>=L:
		print("Possible")
		flag=True
		ans.append(i)
		break
else:
	print("Impossible")

if flag==True:
	while ans[-1]>0:
		ans.append(ans[-1]-1)
	if ans[0]<N-1:
		ans.append(ans[0]+1)
		while ans[-1]<N-2:
			ans.append(ans[-1]+1)
	for i in range(N-2,-1,-1):
		print(ans[i]+1)

Submission status: Accepted

Solution code:
import numpy as np

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

flg = 0
li = []
for i in range(0, int(n) - 1):
    if(knot[i] + knot[i + 1] >= l):
        flg = 1
        print("Possible")
        li.append(i + 1)

        for j in range(i + 2, n):
            li.append(j)
        for j in reversed(range(1, i + 1)):
            li.append(j)
        break

if flg == 0:
    print("Impossible")

for i in reversed(li):
    print(i)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
a = list(map(int, input().split()))
max_value = max_value_index = 0
for index, i in enumerate(zip(a[:-1], a[1:])):
    if max_value < sum(i):
        max_value = sum(i)
        max_value_index = index

print("Possible\n" + "\n".join([str(i) for i in range(1, max_value_index + 1)] + [str(i) for i in range(N - 1, max_value_index, -1)]) if max_value >= L else "Impossible")

Submission status: Accepted

Solution code:
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)
 
# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#
 
def join(s):
    return ''.join(s)
 
#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper
 
nh=zip([1,0,-1,0],[0,1,0,-1])
INF = float('inf')
mod=1000000007
 
###########

n,l=ii()
a=ii()
p=-1
for j in range(n-1):
    if a[j]+a[j+1]>=l:
        p=j

if p==-1:
    print "Impossible"
else:
    print "Possible"
    x=[p+1]
    for j in range(p+2,n):
        x.append(j)
    for j in reversed(range(1,p+1)):
        x.append(j)
    x.reverse()
    for j in x:
        print j

Submission status: Accepted

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

sumL = sum(As)

l,r = 0, N-1
ans = []
cnt = 0

center = -1
for i in range(N-1):
    if As[i]+As[i+1]>=L:
        center = i+1
        break
if center < 0:
    print('Impossible')
else:
    print('Possible')
    for i in range(center-1):
        print(i+1)
    for i in range(N-1, center, -1):
        print(i)
    print(center)
# while sumL>=L and cnt < N-1:
#     # print(l,r,As[l],As[r])
#     if As[l] < As[r]:
#         # print('l<')
#         l += 1
#         sumL -= As[l]
#         ans.append(l)
#         cnt += 1
#     else:
#         # print('r<')
#         r -= 1
#         sumL -= As[r+1]
#         ans.append(r+1)
#         cnt += 1
#     # print('suml',sumL)
# if cnt==N-1:
#     print('Possible')
#     for _a in ans:
#         print(_a)
# else:
#     print('Impossible')

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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


def f():
    n,l = list(map(int, input().split()))
    a = list(map(int, input().split()))
    g = 0
    for i in range(1,n):
        if a[i] + a[i-1] >= l:
            g = i
            break
    if g == 0:
        print('Impossible')
        return
    print('Possible')
    for i in range(1,g):
        print(i)
    for i in range(n-1,g-1,-1):
        print(i)

f()

Submission status: Accepted

Solution code:
NL = input()
NL = "".join(NL).rstrip("\n").split(" ")
N = int(NL[0])
L = int(NL[1])
a = input()
a = "".join(a).split(" ")

for s in range(N-1):
	if int(a[s])+int(a[s+1])>=L:
		Last = s+1
		print("Possible")
		for s in range(N-1):
			if s+1>Last:
				for j in range(N):
					if (N-1-j) ==s:
						#print(Last)
						break
					print(N-1-j)
				break
			if s+1==Last:
				continue
			print(s+1)
		print(Last)
		break
	if s==N-2:
		print("Impossible")

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = list(map(int, input().split()))
flg = False
for i in range(N - 1):
    if A[i] + A[i+1] >= L:
        flg = True
        break
if not flg:
    print("Impossible")
    exit()
else:
    print("Possible")
# 0, 1, ..., i - 1, [i], [i+1], i + 2, ..., N - 1
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:
#!/usr/bin/env python3


def solve(n, l, xs):
    pair_idx = None
    for i in range(n - 1):
        if xs[i] + xs[i + 1] >= l:
            pair_idx = i
            break
    if pair_idx is None:
        return (False, [])
    ans = [x + 1 for x in range(pair_idx)]
    ans.extend(x + 1 for x in range(pair_idx + 1, n - 1)[::-1])
    ans.append(pair_idx + 1)
    return (True, ans)


def main():
    n, l = map(int, input().split())
    xs = list(map(int, input().split()))
    judge, ans = solve(n, l, xs)
    if not judge:
        print("Impossible")
        return
    print("Possible")
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, l = map(int, raw_input().split())
A = map(int, raw_input().split())

for i in xrange(n-1):
    if A[i]+A[i+1] >= l:
        print "Possible"
        print "\n".join(map(str, range(1, i+1) + range(n-1, i+1, -1) + [i+1]))
        break
else:
    print "Impossible"

Submission status: Accepted

Solution code:
def main():
    n, l = (int(s) for s in input().strip().split(' '))
    an = [int (s) for s in input().strip().split(' ')]
    for i in range(1, n):
        if an[i-1] + an[i] >= l:
            print('Possible')
            index = i
            break
    else:
        print('Impossible')
        return
    for i in range(1, index):
        print(i)
    for i in range(n-1, index, -1):
        print(i)
    print(index)
 
main()

Submission status: Accepted

Solution code:
def main():
    n, l = (int(s) for s in input().strip().split(' '))
    an = [int (s) for s in input().strip().split(' ')]
    for i in range(1, n):
        if an[i-1] + an[i] >= l:
            print('Possible')
            index = i
            break
    else:
        print('Impossible')
        return
    for i in range(1, index):
        print(i)
    for i in range(n-1, index, -1):
        print(i)
    print(index)

main()

Submission status: Accepted

Solution code:
n,l=map(int,raw_input().split())
a=map(int,raw_input().split())
fknot=0
for i in xrange(n-1):
    if a[i]+a[i+1]>=l:
        fknot=i+1
if fknot==0:
    print("Impossible")
else:
    print("Possible")
    for i in xrange(n-1,fknot,-1):
        print(i)
    for i in xrange(1,fknot):
        print(i)
    print(fknot)

Submission status: Accepted

Solution code:
import re

class IO_for_Contest(object):
    @staticmethod
    def my_input():
        #return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        n, l = IO_for_Contest.read_n_int(2)
        a = IO_for_Contest.read_n_int(n)
        return l, a

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(int, re.split('\W+', IO_for_Contest.my_input().strip())))[ : n]


def solve():
    l, a = IO_for_Contest.read_from_input()
    result = find_way_how_to_split_ropes(l, a)
    if result is None:
        print('Impossible')
    else:
        print('Possible')
        for x in result:
            print(x)

def find_way_how_to_split_ropes(l, a):
    adjencent_sum = []
    for i in range(len(a) - 1):
        adjencent_sum.append(a[i] + a[i + 1])
    if max(adjencent_sum) < l:
        return None
    x = 0
    result = []
    for y in range(len(adjencent_sum)):
        if adjencent_sum[y] >= l:
            x = y + 1
            break
        result += [y + 1]
    for y in range(len(adjencent_sum) - 1, x - 1, -1):
        result += [y + 1]
    result += [x]
    return result

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

def solve(N, L, As):
    for i in range(N - 1):
        if As[i] + As[i + 1] >= L:
            return list(range(1, i + 1)) + list(range(N - 1, i, - 1))
    return []

N, L, As = read_data()
ans = solve(N, L, As)
if ans:
    print("Possible")
    for i in ans:
        print(i)
else:
    print("Impossible")

Submission status: Accepted

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

k = None
for i in range(N-1):
    if A[i] + A[i+1] >= L:
        k = i
        break
    
if k is None:
    print "Impossible"
else:
    print "Possible"
    for j in range(1,k+1):
        print j
    for j in range(N-1, k, -1):
        print j

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, raw_input().split())
a = map(int, raw_input().split())
b = [a[i]+a[i+1] for i in xrange(N-1)]
maxb = max(b)
maxbi = b.index(maxb)
if maxb < L:
    print 'Impossible'
    exit()
print 'Possible'
for i in xrange(maxbi):
    print i+1
for i in xrange(N-2, maxbi, -1):
    print i+1
print maxbi+1

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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
for _ in range(N-1):
    if tot < L:
        print "Impossible"
        sys.exit()

    na = As[a] + As[a+1]
    nb = As[b] + As[b-1]

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

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

Submission status: Accepted

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

from __future__ import division, print_function, absolute_import, unicode_literals

def main():
    N, L = list(map(int, input().split()))
    a = list(map(int, input().split()))
    pair_L = []
    for car, cdr in zip(a[:-1], a[1:]):
        pair_L.append(car + cdr)
    maximum = max(pair_L)
    # print(maximum)
    if maximum < L:
        print("Impossible")
    else:
        print("Possible")
        index = pair_L.index(maximum) + 1
        i = 1
        while i < index:
            print(i)
            i += 1
        i = N - 1
        while i > index:
            print(i)
            i -= 1
        print(index)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

t = 0
m = 0
for k in range(len(a)-1):
    if a[k]+a[k+1]>=L:
        t = 1
        m = k+1
        break
if t == 0:
    print("Impossible")
    exit()
else:
    print("Possible")
    for k in range(1,m):
        print(k)
    for l in range(len(a)-(k+2)):
        print(len(a)-l-1)
    print(m)

Submission status: Accepted

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

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

if loc < 0:
    print("Impossible")
    exit()

print("Possible")

for i in range(1, loc):
    print(i)
for i in range(n - 1, loc - 1, -1):
    print(i)

Submission status: Accepted

Solution code:
n, l = map(int, raw_input().split())
a = map(int, raw_input().split())
# print a
i = 0
untied  = False
while i < (len(a)-1):
    if a[i] + a[i+1] >= l:
        # print i, a[i]
        untied = True
        break
    i += 1
if untied == False:
    print "Impossible"
    exit()
print "Possible"
for k in xrange(n-1, i+1, -1):
    print k
for k in xrange(1, i+2):
    print k

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = [0]*N

inputStr = input().split()
for i in range(N):
    a[i] = int(inputStr[i])

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

b = check()

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

Submission status: Accepted

Solution code:
n, s = map(int, raw_input().split())
values = list(map(int, raw_input().split()))
found = False
for pos in range(n - 1):
    if values[pos] + values[pos + 1] >= s:
        found = True
        break
if not found:
    print('Impossible')
    import sys
    sys.exit()
    
result = (n - 1) * [ None ]
result[n - 2] = pos + 1
ix = n - 3
for i in range(pos - 1, -1, -1):
    result[ix] = i + 1
    ix -= 1
for i in range(pos + 1, n - 1):
    result[ix] = i + 1
    ix -= 1
print('Possible')
print('\n'.join(map(str, result)))

Submission status: Accepted

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())
b = [0]*(N - 1)
for i in xrange(N - 1):
    b[i] = a[i] + a[i + 1]

mx, idx = 0, 0
for i, bi in enumerate(b):
    if bi > mx:
        mx = bi
        idx = i

if mx >= L:
    print "Possible"
    for i in xrange(idx):
        print i + 1
    for i in xrange(N - 1, idx, -1):
        print i
else:
    print "Impossible"

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N, L = ln()

A = ln()

candidate = -1

for i in xrange(N - 1):
    if A[i] + A[i + 1] >= L:
        candidate = i

if candidate != -1:
    print 'Possible'
    for i in xrange(candidate):
        print i + 1
    for i in xrange(N - 1, candidate, -1):
        print i
else:
    print 'Impossible'

Submission status: Accepted

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,keep):
                print(n)
            for n in range(N-1, keep, -1):
                print(n)
            print(keep)
            return
    print("Impossible")
        
solve()

Submission status: Accepted

Solution code:
from sys import stdin, stdout
from itertools import repeat
def main():
    n, l = map(int, stdin.readline().split())
    a = map(int, stdin.read().split(), repeat(10, n))
    for i in xrange(n - 1):
	if a[i] + a[i+1] >= l:
            ans = range(1, i + 1) + range(n - 1, i + 1, -1) + [i + 1]
            stdout.write('Possible\n')
            stdout.write('\n'.join(map(str, ans)))
            stdout.write('\n')
            return
    print "Impossible"
main()

Submission status: Accepted

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

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)
		else:
			break
	for i in reversed(range(1, N)):
		if i != Mi:
			print(i)
		else:
			break
	print(Mi)

Submission status: Accepted

Solution code:
N,L = map(int, raw_input().split())
a = map(int, raw_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()))

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