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

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

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

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

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

N, L = getNM()
A = getList()

pos = deque([])
for i in range(N):
    pos.append([A[i], i, i + 1])

left = sum(A)

ans = []
flag = True
for _ in range(N - 1):
    if left < L:
        flag = False
        break
    # 先頭を取り出す
    if pos[0] <= pos[-1]:
        u, _, a = pos.popleft()
        ans.append(a)
        left -= u
    else:
        u, a, _ = pos.pop()
        ans.append(a)
        left -= u

if flag:
    print('Possible')
    for i in ans:
        print(i)
else:
    print('Impossible')

Submission status: Wrong Answer

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

i = 0

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

sa = sum(As)
l = 1
r = len(As) - 1
rlt = []

while len(As) > 1:
  if sa < L:
    print('Impossible')
    exit()
  if As[0] < As[-1]:
    sa -= As[0]
    As.popleft()
    rlt.append(l)
    l += 1
  else:
    sa -= As[-1]
    As.pop()
    rlt.append(r)
    r -= 1
    
print('Possible')
for s in rlt:
  print(s)

Submission status: Wrong Answer

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

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

def main():
    mod=10**9+7
    N,L=MI()
    A=LI()
    S=sum(A)
    
    from collections import deque
    dq=deque()
    
    for i in range(N):
        dq.append((A[i],i))
        
    flag=1
    ans=[]
    for i in range(N-1):
        a,ai=dq.pop()
        b,bi=dq.popleft()
        
        if S>=L:
            if a>=b:
                dq.append((a,ai))
                S-=b
                ans.append(bi+1)
            else:
                dq.appendleft((b,bi))
                S-=a
                ans.append(ai)
        else:
            flag=0
            break
        
    if flag==0:
        print("Impossible")
    else:
        print("Possible")
        for i in ans:
            print(i)
        
        
    
    
    

main()

Submission status: Wrong Answer

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

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

res = -1

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

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

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

for i in ans:
    print(i+1)

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

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
ret = []
l = 0
r = n-1
d = sum(a)
for i in range(n-1):
    if d < k:
        print('Impossible')
        exit()
    if a[l]<a[r]: #l saiyou
        d -= a[l]
        ret.append(l+1)
        l += 1
    else:         #r saiyou
        d -= a[r]
        ret.append(r)
        r -= 1
print('Possible')
print('\n'.join(map(str, ret)))

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
ret = []
l = 0
r = n-1
d = sum(a)
while l < r:
    if d < k:
        print('Impossible')
        exit()
    if a[l]<a[r]: #l saiyou
        d -= a[l]
        ret.append(l+1)
        l += 1
    else:         #r saiyou
        d -= a[r]
        ret.append(r)
        r -= 1
print('Possible')
print('\n'.join(map(str, ret)))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
import numpy as np
#decimal.getcontext().prec = 10

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

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

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
import numpy as np
#decimal.getcontext().prec = 10

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

tmp = sum(a)
if tmp < L:
	print("Impossible")
	exit()
tie = deque(range(1, N))
cnt = N-1

ans = []
while 1 < cnt:
	cnt -= 1
	if a[0] < a[-1] and L <= tmp-a[0]:
		tmp -= a.popleft()
		ans.append(tie.popleft())
	elif a[0] >= a[-1] and L <= tmp-a[-1]:
		tmp -= a.pop()
		ans.append(tie.pop())
	else:
		print("Impossible")
		break
else:
	ans.append(tie.pop())
	print("Possible")
	print(*ans, sep= "\n")

Submission status: Wrong Answer

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

count = 0
A = []

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

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

Submission status: Wrong Answer

Solution code:
from collections import deque
def solve():
  ans = ['Possible']
  N, L = map(int, input().split())
  A = list(map(int, input().split()))
  left,right = 0,N-1
  total = sum(A)
  if total<L:
    return ['Impossible']
  for _ in range(N-2):
    if A[left]<=A[right]:
      ans.append(left+1)
      total -= A[left]
      left += 1
    else:
      total -= A[right]
      ans.append(right)
      right -= 1
    if total<L:
      return ['Impossible']
  ans.append(right)
  return ans
print(*solve(),sep='\n')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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


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

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

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


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 隣り合う和がL未満ならそもそもimpossible
# ならば隣り合う和がL以上ならば？ -> そこから連続して隣り合うやつをどうやって足しても常にL以上

n, l = map(int, input().split())
a = list(map(int, input().split()))
idx = 0
for i in range(1, n):
    if a[i - 1] + a[i] >= l:
        idx = i
        break
if idx == 0:
    print("impossibe")
    exit()

print("possible")

ans = [idx]
for i in range(idx - 1, 0, -1):
    ans.append(i)
for i in range(idx + 1, n):
    ans.append(i)
for a in ans[::-1]:
    print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

# 全体がLを超えていることを確認しながら、左端および右端の短いほうを切っていく
from collections import deque
q = deque(A)
total = sum(A)

ans = []
l_ind = 1
r_ind = len(A) - 1
while len(q) > 1:
  if total < L:
    print("Impossible")
    break
  left = q[0]
  right = q[-1]
  if left < right:
    left = q.popleft()
    ans.append(l_ind)
    l_ind += 1
    total -= left
  else:
    right = q.pop()
    ans.append(r_ind)
    r_ind -= 1
    total -= right
else:
  print("Possible")
  for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import sys

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

N, L, *A = map(int, read().split())

def main(L, A):
    N = len(A)
    is_long = [x + y >= L for x, y in zip(A, A[1:])]
    if not any(is_long):
        print('Impossible')
        return
    print('Possible')
    i = is_long.index(True)
    nums = list(range(1, N))
    nums.remove(i + 1)
    nums.append(i + 1)
    print(*nums, sep='\n')

main(L, A)

Submission status: Wrong Answer

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,l = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    pa = a[0]
    mi = -1
    for i,ai in enumerate(a[1::]):
        if pa+ai >= l:
            print("Possible")
            mi = i
            break
        pa = ai
    if mi == -1:
        print("Impossible")
        exit()
    for i in range(mi):
        print(i)
    for i in range(n-mi):
        print(n-i-1)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,l = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    pa = a[0]
    mi = -1
    for i,ai in enumerate(a[1::]):
        if pa+ai >= l:
            print("possible")
            mi = i
            break
        pa = ai
    if mi == -1:
        print("Impossible")
        exit()
    for i in range(mi):
        print(i)
    for i in range(n-mi):
        print(n-i-1)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

if flag==0:
    print("Impossible")
else:
    print("Possible")
    if i>0:
        for j in range(1,i+1):
            print(j)
    if i+2<n:
        for j in range(i+2,n):
            print(j)
    print(i+1)

Submission status: Wrong Answer

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

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

if flg == 0:
    print('Impossible')
else:
    print('Possible')
    last += 1
    x = list(range(last+1,N))
    y = list(range(1,last))
    for a in x:
        print(a)
    for a in y:
        print(a)

    print(last)

Submission status: Wrong Answer

Solution code:
N,L=map(int, input().split())
A=list(map(int, input().split()))
tw=A[0]+A[1]
for i in range(N-1):
  tw=max(tw,A[i]+A[i+1])
if tw<L:
  print('Impossible')
  exit()

print('Possible')
left,right=0,N-1
cnt=0
while cnt<N-1:
  if A[left]<=A[right]:
    print(left+1)
    left+=1
    cnt+=1
  else:
    print(right)
    right-=1
    cnt+=1

Submission status: Wrong Answer

Solution code:
K=10**10
import sys
N,L=map(int,input().split())
T=list(map(int,input().split()))
for i in range(N-1):
  if T[i]+T[i+1]>=L:
    K=i
    print("Possible")
    break
if K==10**10:
  print("Impossible")
  sys.exit()
K=K+1
R=list(range(1,K))
R.extend(list(range(K+1,N)))
R.append(K)
for i in range(N-1):
  print(R[i])

Submission status: Wrong Answer

Solution code:
K=10**10
import sys
N,L=map(int,input().split())
T=list(map(int,input().split()))
for i in range(N-1):
  if T[i]+T[i+1]>=L:
    K=i
    print("Possible")
    break
if K==10**10:
  print("Impossible")
  sys.exit()
K=K+1
R=list(range(1,K))
R.extend(list(range(K+1,N)))
R.append(K)
R=list(map(str,R))
for i in range(N-1):
  print(R[i])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,L=map(int,input().split())
    a=tuple(map(int,input().split()))
    S=sum(a)
    left,right=0,N-1
    ans=[]
    for i in range(N-1):
        if S<L:
            print('Impossible')
            exit()
        if a[left]<a[right]:
            S-=a[left]
            ans.append(left+1)
            left+=1
        else:
            S-=a[right]
            ans.append(right)
            right-=1
    print('Possible')
    for row in ans:
        print(row)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,L=map(int,input().split())
    a=tuple(map(int,input().split()))
    S=sum(a)
    left,right=0,N-1
    ans=[]
    for i in range(N-1):
        if S<L:
            print('Impossible')
            exit()
        if a[left]<a[right]:
            S-=a[left]
            left+=1
            ans.append(left+1)
        else:
            S-=a[right]
            right-=1
            ans.append(right+1)
    print('Possible')
    for row in ans:
        print(row)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
N,L=map(int,input().split())
a=list(map(int,input().split()))
d=deque()
su=0
flag=1
for i in range(N):
    d.append(a[i])
    su=su+a[i]
l=1
r=N-1
ans=[]
while len(d)>1:
    if su>=L:
        v1=d.popleft()
        v2=d.pop()
        if v1<=v2:              #v1の方が小さいなら
            d.append(v2)        #v2を戻す
            ans.append(l)
            su=su-v1
            l=l+1
        else:
            d.appendleft(v1)
            ans.append(r)
            su=su-v2
            r=r-1
    else:
        flag=0
        break
    #print(d)
    #input()
if flag==0:
    print("Impossible")
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()))
d=deque()
su=0
flag=1
for i in range(N):
    d.append(a[i])
    su=su+a[i]
l=1
r=N-1
ans=[]
while len(d)>1:
    if su>=L:
        v1=d.popleft()
        v2=d.pop()
        if v1<=v2:              #v1の方が小さいなら
            d.append(v2)        #v2を戻す
            ans.append(l)
            l=l+1
        else:
            d.appendleft(v1)
            ans.append(r)
            r=r-1
    else:
        flag=0
        break
    #print(d)
    #input()
if flag==0:
    print("Impossible")
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()))

SumA = sum(A)
count, count_rev = 0, 0

for i in range(N):
  if SumA < L:
    break
  else:
    count += 1
  SumA -= A[i]

SumA = sum(A)

for i in range(N-1,-1,-1):
  if SumA < L:
    break
  else:
    count_rev += 1
  SumA -= A[i]

if count or count_rev == N-1:
  print('Possible')
  if count == N-1:
    L = [int(i) for i in range(1,N)]
  else:
    L = [int(i) for i in range(N-1,0,-1)]
  for l in L:
    print(l)
  exit()

print('Impossible')

Submission status: Wrong Answer

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

SumA = sum(A)
count, count_rev = 0, 0

for i in range(N-1):
  if SumA < L:
    break
  else:
    count += 1
  SumA -= A[i]

SumA = sum(A)

for i in range(N-1,0,-1):
  if SumA < L:
    break
  else:
    count_rev += 1
  SumA -= A[i]

if count or count_rev == N-1:
  print('Possible')
  if count == N-1:
    L = [int(i) for i in range(1,N)]
  else:
    L = [int(i) for i in range(N-1,0,-1)]
  for l in L:
    print(l)
  exit()

print('Impossible')

Submission status: Wrong Answer

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

a=[int(x) for x 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(j)
  print("Possible")
  for i in range(j):
    print(i+1)
  for i in range(n-1,j,-1):
    print(i+1)

Submission status: Wrong Answer

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

a=[int(x) for x 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(j)
  print("Possible")
  for i in range(j):
    print(i+1)
  for i in range(n-1,j,-1):
    print(i+1)

Submission status: Wrong Answer

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

a=[int(x) for x in input().split()]

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

Submission status: Wrong Answer

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

a=[int(x) for x 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(n-1,j,-1):
    print(i)

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

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

N,L = inputIL()
A = inputIL()


indexs = []

M = max(A)
for i in range(N):
  if A[i]==M:
    indexs.append(i)

for index in indexs:
  if index == 0:
    if A[0]+A[1] >= L:
      print("Possible")
      for i in range(N-1)[::-1]:
        print(i+1)
      exit()

  elif index == N-1:
    if A[N-1]+A[N-2] >= L:
      print("Possible")
      for i in range(N-1):
        print(i+1)
      exit()      

  else:
    if A[index]+A[index-1] >= L:
      print("Possible")
      for i in range(index,N-1)[::-1]:
        print(i+1)
      for i in range(index):
        print(i+1)
      exit()
    elif A[index]+A[index+1] >= L:
      print("Possible")
      for i in range(index):
        print(i+1)
      for i in range(index,N-1)[::-1]:
        print(i+1)
      exit()

print("Impossible")

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

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

N,L = inputIL()
A = inputIL()


M = max(A)
for i in range(N):
  if A[i]==M:
    index = i

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

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
flag=False
for i in range(0,n-1):
    if not flag:
        if a[i]+a[i+1]>=l:
            cnt=i+1
            flag=True

if not flag:
    print("Impossible")
    exit()

ans=[cnt]

for i in range(1,cnt):
    ans.append(i)
for i in range(cnt+1,n):
    ans.append(i)
ans=ans[::-1]
print("Possible")
for i in range(len(ans)):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
INF = 10 ** 15
MOD = 10 ** 9 + 7 
def main():
    N,L = map(int,input().split())
    A = list(map(int,input().split()))
    X = sum(A)
    l = 0
    r = N - 1
    ans = []
    for _ in range(N - 1):
        if X < L:
            break
        if A[l] < A[r]:
            X -= A[l]
            ans.append(l + 1)
            l += 1
        else:
            X -= A[r]
            ans.append(r)
            r -= 1
    if len(ans) == N - 1:
        print('Possible')
        print('\n'.join(map(str,ans)))
    else:
        print('Impossible')
if __name__ == '__main__':
    main()