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:
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(i+1,n):
            print(j)
        print(i)
        exit()

print('Impossible')

Submission status: Wrong Answer

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

print('Impossible')

Submission status: Wrong Answer

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(s+1,N-1):
    L.append(i+1)
L.append(s+1)
#print(L,s)
print('\n'.join(map(str,L)))

Submission status: Wrong Answer

Solution code:
import sys
N,L=map(int,input().split())
A=[int(i) for i in input().split()]
s=10**9
for i in range(N-1):
    if A[i]+A[i+1]>=L:
        s=i
        break
if s==10**9:
    print('Impossible')
    sys.exit()
print('Possible')
L=[]
for i in range(s):
    L.append(i+1)
for i in range(s+1,N-1):
    L.append(i+1)
L.append(s+1)
#print(L,s)
print('\n'.join(map(str,L)))

Submission status: Wrong Answer

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
    while index < i:
        print(i)
        i -= 1

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 += list(range(start))
  if start != N-2:
    ans += reversed(list(range(start+1, N-1)))
  ans.reverse()
  for a in ans:
    print(a+1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac

n,l=map(int,input().split())
*a,=map(int,input().split())
*b,=ac([0]+a)

left,right=0,n
result=[]

for _ in range(n-1):
    length=b[right]-b[left]
    if length>=l:
        if a[left]>a[right-1]:
            right-=1
            result.append(right)
        elif a[left]<=a[right-1]:
            left+=1
            result.append(left)
    else:
        print("Impossible")
        break
else:
    print("Possible")
    for i in result:
        print(i)

Submission status: Wrong Answer

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

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

if not CanRemain: print("impossible")
else:
    print("possible")
    for i in range(1, CanRemain[-1]): 
        if i not in CanRemain: print(i)
    for i in reversed(range(CanRemain[-1]+1, N)): print(i)
    for num in CanRemain: print(num)

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
l = map(int, raw_input().split())
totallen = sum(l)
i = 0
j = n - 2
ans = []
while i <= j:
	if totallen < k:
		break
	else:
		if l[i] < l[j]:
			ans.append(i + 1)
			totallen -= l[i]
			i += 1
		else:
			ans.append(j + 1)
			totallen -= l[j+1]
			j -= 1
if len(ans) == n - 1:
	print "Possible"
	for i in ans:
		print i 
else:
	print "Impossible"

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
l = map(int, raw_input().split())
totallen = sum(l)
h = []
i = 0
j = n - 2
ans = []
while i <= j:
	if totallen < k:
		break
	else:
		if l[i] < l[j]:
			ans.append(i + 1)
			i += 1
		else:
			ans.append(j + 1)
			j -= 1
if len(ans) == n - 1:
	print "Possible"
	for i in ans:
		print i 
else:
	print "Impossible"

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if a[n - 1] + a[n - 2] >= l:
  print("Possible")
else:
  print("Impossible")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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-1,ans,-1))+[ans]
for i in range(N-1):
    print(Ans[i]+1)

Submission status: Wrong Answer

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(1+ans,N-1))+[ans]
for i in range(N-1):
    print(Ans[i]+1)

Submission status: Wrong Answer

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

poss = False

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

if a[0]+a[1] >= l:
    ans = [i for i in range(n-1,0,-1)]
    print("Possible")
    for ai in ans:
        print(ai)
        
elif a[-1]+a[-2] >= l:
    ans = [i for i in range(1,n)]
    print("Possible")
    for ai in ans:
        print(ai)
        
else:
    print("Impossible")

Submission status: Wrong Answer

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:
    for i in range(1,n):
        if i!=ans:print(i)
    print(ans)

Submission status: Wrong Answer

Solution code:
N,L=map(int,input().split())
A=list(map(int,input().split()))
B=[]
#print(A)
s=0
e=len(A)-1
for i in range(N-1):
    
    if A[s]<=A[e]:
        B.append(s+1)
        s+=1
    else:
        B.append(e)
        e-=1
if (A[s]+A[e])<L:
    print("Impossible")
else:
    print("Possible")
    for j in range(len(B)):
        print(B[j])

Submission status: Wrong Answer

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,n):
            if j!=i:
                print(j)
        print(i)
        break
else:
    print("Impossible")

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
a = [int(x) for x in input().split()]
b = [x+y for (x,y) in zip(a+[0],[0]+a)]
if max(b) < l:
    print("Impossible")
else:
    print("Possible")
    ans = [x for x in range(1,n) if x != b.index(max(b))] + [b.index(max(b))]
    for x in ans:
        print(x)

Submission status: Wrong Answer

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:
            pass
        else:
            print(i + 1)

    if connect:
        print(knot + 1)

Submission status: Wrong Answer

Solution code:
N, L, *a = map(int, open(0).read().split())
for i, (n, m) in enumerate(zip(a, a[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: Wrong Answer

Solution code:
n,l = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
s,x,y,ans = sum(a),0,n-1,[]
while l<=s and x!=y:
	if a[x]<a[y]:
		ans.append(x+1)
		x,s = x+1,s-a[x]
	else:
		ans.append(y)
		y,s = y-1,s-a[y]
if len(ans)==n-1:
	print("Possible")
	for i in ans: print(i)
else: print("Impossible")

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
a=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=S[i]+a[i]
#S[r+2]-S[l+1]
L=[]
l=0
r=N-1
#i,i,i+1
for i in range(N):
    if a[l]+a[l+1]<a[r-1]+a[r]:
        L.append(l)
        l+=1
    else:
        L.append(r)
        r-=1
    if S[r+1]-S[l]<K:
        break
if len(L)<N-1:
    print("Impossible")
else:
    print("Possible")
    for i in L:
        print(i)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

length = sum(A)
A = deque(list(enumerate(A)))

ans = []
while len(A) > 1:
    if length < L:
        print("Impossible")
        break

    if A[0][1] <= A[-1][1]:
        n, a = A.popleft()
        ans.append(n+1)
        length -= a
    else:
        n, a = A.pop()
        ans.append(n)
        length -= a

else:
    print("Possible")
    print(*ans, sep="\n")

Submission status: Wrong Answer

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

length = sum(A)
A = deque(list(enumerate(A)))

ans = []
while len(A) > 1:
    if length < L:
        print("Impossible")
        break

    if A[0][1] < A[-1][1]:
        n, a = A.popleft()
        ans.append(n+1)
        length -= a
    else:
        n, a = A.pop()
        ans.append(n)
        length -= a

else:
    print("Possible")
    print(*ans, sep="\n")

Submission status: Wrong Answer

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:
	muri = False
	mijikai = []

	if a[0] + a[1] < l:
		mijikai.append(1)
	for i in range(n - 2):
		if a[i] + a[i + 1] < l and a[i + 1] + a[i + 2] < l:
			muri = True
			break
		elif a[i + 1] + a[i + 2] < l:
			mijikai.append(i + 2)

	if muri:
		print("Impossible")
	else:
		print("Possible")
		for m in mijikai:
			print(m)
		for i in range(1, n):
			if i not in mijikai:
				print(i)

Submission status: Wrong Answer

Solution code:
N,L = list(map(int,input().split(" ")))
ai = list(map(int,input().split(" ")))
num_list = [i+1 for i in range(N-1)]
resolve_list = []
lopeIsSmall = False

while(len(ai)!=1):
    if(sum(ai)<L):
        lopeIsSmall = True
        break

    if(ai[0]>ai[-1]):
        resolve_list.append(num_list.pop())
        ai.pop()
    else:
        resolve_list.append(num_list.pop(0))
        ai.pop(0)

if lopeIsSmall:
    print("Impossible")
else:
    print("Possible")
    for num in resolve_list:
        print(num)

Submission status: Wrong Answer

Solution code:
N,L = list(map(int,input().split(" ")))
ai = list(map(int,input().split(" ")))
num_list = [i+1 for i in range(N)]
resolve_list = []
lopeIsSmall = False

while(len(ai)!=1):
    if(sum(ai)<L):
        lopeIsSmall = True
        break

    if(ai[0]>ai[-1]):
        resolve_list.append(num_list.pop())
        ai.pop()
    else:
        resolve_list.append(num_list.pop(0))
        ai.pop(0)

if lopeIsSmall:
    print("Impossible")
else:
    print("Possible")
    for num in resolve_list:
        print(num)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, L = map(int, input().split())
a = deque(list((map(int, input().split()))))
a_sum = sum(a)
ans = []
musubi_left = 1
musubi_right = N-1
for _ in range(N-1):
    if a_sum < L:
        print("Impossible")
        exit()
    if a[0] < a[-1]:
        ans.append(musubi_left)
        cut = a.popleft()
        a_sum -= cut
        musubi_left += 1
    else:
        ans.append(musubi_right)
        cut = a.pop()
        a_sum -= cut
        musubi_right -= 1
print("Possible")
for i in ans:
    print(i)

Submission status: Wrong Answer

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(a[j])
    for k in range(count,N)[::-1]:
        b.append(a[k])
    
    print(res)
    for l in range(len(b)):
        print(b[l])
else:
    print(res)

Submission status: Wrong Answer

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
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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  5 22:01:07 2016

@author: dotha
"""




def say(l,r):
    for i in range(l,r):
        print(i+1)
    if l>r:
        for i in range(l,r,-1):
            print(i)



def solver(N,L,a):
    for i in range(N-2):
        if a[i+1]+a[i] >= L:
            break
    else:
        print('Impossible')
        return
    print('Possible')
    left = 0
    for i in range(N-1):
        if a[i+1]+a[i] >= L:
            say(left,i)
            left = i
        if left == N-2:
            print(left+1)
            break
    else:
        say(N-1,left)
        
            









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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  5 22:01:07 2016

@author: dotha
"""




def say(l,r):
    for i in range(l,r):
        print(i+1)
    if l>r:
        for i in range(l,r,-1):
            print(i)



def solver(N,L,a):
    for i in range(N-2):
        if a[i+1]+a[i] >= L:
            break
    else:
        print('Impossible')
        return
    print('Possible')
    left = 0
    for i in range(N-1):
        if a[i+1]+a[i] > L:
            say(left,i)
            left = i
        if left == N-2:
            print(left+1)
            break
    else:
        say(N-1,left)
        
            









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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  5 22:01:07 2016

@author: dotha
"""




def say(l,r):
    for i in range(l,r):
        print(i+1)
    if l>r:
        for i in range(l,r,-1):
            print(i-1)



def solver(N,L,a):
    for i in range(N-2):
        if a[i+1]+a[i] >= L:
            break
    else:
        print('Impossible')
        return
    print('Possible')
    left = 0
    for i in range(N-1):
        if a[i+1]+a[i] > L:
            say(left,i)
            left = i
        if left == N-2:
            print(left+1)
            break
    else:
        say(N-1,left)
        

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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
print(pos)
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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,l=map(int,raw_input().split())
a=map(int,raw_input().split())
w=sum(a)
x=1
y=n-1
f=0
ans=[]
while 1:
    if a[x-1]<a[y]:
        if w>=l:
            ans.append(x)
            w-=a[x-1]
            x+=1
            f+=1
        else:
            break
    else:
        if w>=l:
            ans.append(y)
            w-=a[y]
            y-=1
            f+=1
        else:
            break
    if x==y+1:
        break
if f!=n-1:
    print 'Impossible'
else:
    print 'Possible'
    for i in ans:
        print i

Submission status: Wrong Answer

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
    l+=[la+1]
    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: Wrong Answer

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
    l+=[la+1]
    for i in range(1, la+1) : print(i)
    for i in range(la+2, N) : print(i)
    print(la+1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 = []
    while len(A) > 2:
        x = A[0] + A[1]
        y = A[-1] + A[-2]
        if x < L and y < L:
            s = 0
            for i in A:
                s += i
                if s >= L : break
            if s < L:
                print('Impossible')
                return
        if x < y:
            l += [a]
            a += 1
            A = A[1:]
        else:
            l += [b]
            b -= 1
            A = A[:-1]
    print('Possible')
    l+=[a]
    for i in l : print(i)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,l = map(int, input().split())
alist = list(map(int, input().split()))
rrr=[]
lll=[]
for i in range(len(alist)):
    lll.append([alist[i],i+1])
lll[len(lll)-1][1]= -1
rrr = sorted(lll, reverse=True)
lll.sort()
x = rrr[0][0]+rrr[1][0]
i=0
ii=1
if(x < l):
    print("Impossible")
else:
    print("Possible")
    while(ii<n):
        if(lll[i][1]== -1):
            i+=1
            continue
        print(lll[i][1])
        ii+=1
        i+=1

Submission status: Wrong Answer

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

broken = [0 for _ in range(len(a)-1)]
if sum(a) < M:
    print "Impossible"
    exit()

def choose(start):
    length = a[start]
    i = start + 1
    while length < M:
        if i >= len(a):
            return -1
        length += a[i]
        i += 1
    return i - 1

def minidx(start, arr):
    minelem = 10 ** 9
    idx = -1
    for i, elem in enumerate(arr):
        if elem <= minelem and broken[start + i] == 0:
            minelem = elem
            idx = i
    return idx + start

def findfirst(cond, arr):
    for i, elem in enumerate(arr):
        if cond(elem):
            return i
    return -1


start = 0
r = 1
# print a
i = 0
while True:
    end = choose(start)
    if end == -1:
        break
    idx = minidx(start, a[start:end+1])
    broken[idx] = r
    start = findfirst(lambda b: b == 0, broken)
    r += 1
    if r > len(broken): break
    # print start
    # print broken
    # i += 1
    # if i == 3: break

print "Possible"
for elem in broken:
    print elem

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,l=map(int,raw_input().split())
a=map(int,raw_input().split())
w=sum(a)
x=1
y=n-1
f=0
ans=[]
while 1:
    if a[x-1]<a[y]:
        if w>=l:
            ans.append(x)
            w-=a[x-1]
            x+=1
        else:
            break
    else:
        if w>=l:
            ans.append(y)
            w-=a[y]
            y-=1
        else:
            break
    if x==y+1:
        f=1
        break
if f==0:
    print 'Impossible'
else:
    print 'Possible'
    for i in ans:
        print i

Submission status: Wrong Answer

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] >= 50:
        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: Wrong Answer

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

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        n, l = map(int, input().split())
        a = list(map(int, input().split()))

        left = 0
        right = n - 1
        tmp = a[:]
        while len(tmp) > 1:
            if sum(tmp) < l:
                print('Impossible')
                return
            if tmp[0] <= tmp[-1]:
                # print(left+1)
                left += 1
                tmp = tmp[1:]
            else:
                # print(right)
                right -= 1
                tmp = tmp[:-1]
            print(tmp)
        print('Possible')
        
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Wrong Answer

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))
    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: Wrong Answer

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
    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))
    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: Wrong Answer

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

t = 0
for k in range(len(a)-1):
    if a[k]+a[k+1]>=L:
        t = 1
if t == 0:
    print("Impossible")
    exit()

ans = []
f = 0
l = len(a)-1
while l-f>1:
    if 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:
#!/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
    if pair_idx is None:
        return (False, [])
    ans = [x + 1 for x in range(n - 1) if x != pair_idx]
    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: 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

t = 0
for k in range(len(a)-1):
    if a[k]+a[k+1]>=L:
        t = 1
if t == 0:
    print("Impossible")
    exit()

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()))
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
    elif A[i] == A[j]:
        # 隣りだったらどっちでも良い
        if i + 1 == j:
            sum_A -= A[i]
            ans.append(i + 1)
            i += 1
        else:
            new_i = i + 1
            new_j = j - 1
            while A[new_i] == A[new_j]:
                if new_i >= new_j:
                    break
                new_i += 1
                new_j -= 1
            # print("new_i", new_i)
            # print("new_j", new_j)
            if A[new_i] < A[new_j]:
                cut = i
            else:
                cut = j
            # print("cut", cut)
            if cut == i:
                sum_A -= A[i]
                ans.append(i + 1)
                i += 1
            else:
                sum_A -= A[j]
                ans.append(j)
                j -= 1
    else:
        sum_A -= A[j]
        ans.append(j)
        j -= 1