Submission details
Task:3SUM
Sender:aalto26gm_007
Submission time:2026-10-19 17:04:44 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.04 sdetails
#20.04 sdetails
#30.04 sdetails
#40.04 sdetails
#50.04 sdetails
#60.04 sdetails
#70.04 sdetails
#80.04 sdetails
#90.05 sdetails
#100.00 sdetails
#110.10 sdetails
#120.12 sdetails
#130.07 sdetails
#140.07 sdetails
#150.07 sdetails
#160.12 sdetails
#170.27 sdetails
#180.05 sdetails
#190.07 sdetails
#200.12 sdetails
#210.08 sdetails
#220.07 sdetails
#230.04 sdetails

Code

import sys
from bisect import bisect_left
def main():
    data = sys.stdin.buffer.read().split()
    n, target = int(data[0]), int(data[1])
    if target<=2:
        print("IMPOSSIBLE")
        exit()

    l = list(zip(list(map(int, data[2:])), range(1,n+1)))
    print(l)
    l.sort()
    print(l)
    l, indexes = zip(*l)
    print(l, indexes)
    for i in range(n-2):
        remaining = target - l[i]
        print(l[i], ",  remaining:" , remaining)
        if remaining<=0:
            print("IMPOSSIBLE")
            exit()



        c1 = max(bisect_left(l, remaining//2, lo=i+1) -1, i+1)
        c2 = c1+1
        while True:
            print(c1, c2)

            lc1 = l[c1]
            lc2 = l[c2]
            val = l[i]+lc1+lc2
            if val == target:
                print(l[i], lc1, lc2)
                exit()
            elif val < target:
                c2+=1
                if c2==n:
                    break
            else :
                c1-=1
                if c1 == i:
                    break
    print("IMPOSSIBLE")

main()

Test details

Test 1

Verdict:

input
1 3
1

correct output
IMPOSSIBLE

user output
[(1, 1)]
[(1, 1)]
(1,) (1,)
IMPOSSIBLE

Test 2

Verdict:

input
3 5
1 3 2

correct output
IMPOSSIBLE

user output
[(1, 1), (3, 2), (2, 3)]
[(1, 1), (2, 3), (3, 2)]
(1, 2, 3) (1, 3, 2)
1 ,  remaining: 4
1 2
...

Test 3

Verdict:

input
3 6
1 3 2

correct output
1 3 2

user output
[(1, 1), (3, 2), (2, 3)]
[(1, 1), (2, 3), (3, 2)]
(1, 2, 3) (1, 3, 2)
1 ,  remaining: 5
1 2
...

Test 4

Verdict:

input
3 7
3 2 1

correct output
IMPOSSIBLE

user output
[(3, 1), (2, 2), (1, 3)]
[(1, 3), (2, 2), (3, 1)]
(1, 2, 3) (3, 2, 1)
1 ,  remaining: 6
1 2
...

Test 5

Verdict:

input
7 3
2 1 1 2 2 1 1

correct output
2 3 7

user output
[(2, 1), (1, 2), (1, 3), (2, 4...

Test 6

Verdict:

input
7 4
1 1 2 2 1 2 1

correct output
1 2 6

user output
[(1, 1), (1, 2), (2, 3), (2, 4...

Test 7

Verdict:

input
7 5
1 2 1 2 2 1 1

correct output
1 2 5

user output
[(1, 1), (2, 2), (1, 3), (2, 4...

Test 8

Verdict:

input
7 6
2 1 1 1 1 2 2

correct output
1 6 7

user output
[(2, 1), (1, 2), (1, 3), (1, 4...

Test 9

Verdict:

input
5000 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1 2 5000

user output
[(1, 1), (1, 2), (1, 3), (1, 4...

Test 10

Verdict:

input
5000 4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
IMPOSSIBLE

user output
(empty)

Test 11

Verdict:

input
5000 6
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
714 3518 4240

user output
[(1, 1), (1, 2), (1, 3), (1, 4...

Test 12

Verdict:

input
5000 919900245
663612758 9075403 585385629 98...

correct output
2787 465 2266

user output
[(663612758, 1), (9075403, 2),...

Test 13

Verdict:

input
5000 999989608
12983 25966 38949 51932 64915 ...

correct output
IMPOSSIBLE

user output
[(12983, 1), (25966, 2), (3894...

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 46, in <module>
    main()
  File "/box/input/code.py", line 31, in main
    lc2 = l[c2]
IndexError: tuple index out of range

Test 14

Verdict:

input
5000 1000000000
65536 131072 196608 262144 327...

correct output
IMPOSSIBLE

user output
[(65536, 1), (131072, 2), (196...

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 46, in <module>
    main()
  File "/box/input/code.py", line 31, in main
    lc2 = l[c2]
IndexError: tuple index out of range

Test 15

Verdict:

input
5000 642700000
6427 12854 19281 25708 32135 3...

correct output
IMPOSSIBLE

user output
[(6427, 1), (12854, 2), (19281...

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 46, in <module>
    main()
  File "/box/input/code.py", line 31, in main
    lc2 = l[c2]
IndexError: tuple index out of range

Test 16

Verdict:

input
5000 919900246
663612758 9075403 585385629 98...

correct output
193 1698 4019

user output
[(663612758, 1), (9075403, 2),...

Test 17

Verdict:

input
5000 919900247
663612758 9075403 585385629 98...

correct output
4258 470 1911

user output
[(663612758, 1), (9075403, 2),...

Test 18

Verdict:

input
5000 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 ...

correct output
4998 4999 5000

user output
[(6, 1), (6, 2), (6, 3), (6, 4...

Test 19

Verdict:

input
5000 919900247
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
IMPOSSIBLE

user output
[(1, 1), (1, 2), (1, 3), (1, 4...

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 46, in <module>
    main()
  File "/box/input/code.py", line 31, in main
    lc2 = l[c2]
IndexError: tuple index out of range

Test 20

Verdict:

input
4999 919900245
9075403 585385629 987230075 83...

correct output
2786 464 2265

user output
[(9075403, 1), (585385629, 2),...

Test 21

Verdict:

input
5000 1000000000
261323261 25262018 237798562 3...

correct output
IMPOSSIBLE

user output
[(261323261, 1), (25262018, 2)...

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 46, in <module>
    main()
  File "/box/input/code.py", line 31, in main
    lc2 = l[c2]
IndexError: tuple index out of range

Test 22

Verdict:

input
5000 76305003
1 5088 10175 15262 20349 25436...

correct output
IMPOSSIBLE

user output
[(1, 1), (5088, 2), (10175, 3)...

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 46, in <module>
    main()
  File "/box/input/code.py", line 31, in main
    lc2 = l[c2]
IndexError: tuple index out of range

Test 23

Verdict:

input
2 6
2 2

correct output
IMPOSSIBLE

user output
[(2, 1), (2, 2)]
[(2, 1), (2, 2)]
(2, 2) (1, 2)
IMPOSSIBLE