Submission details
Task:3SUM
Sender:aalto26gm_008
Submission time:2026-10-19 17:23:18 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#20.04 sdetails
#30.04 sdetails
#40.04 sdetails
#50.04 sdetails
#60.04 sdetails
#70.04 sdetails
#80.00 sdetails
#90.04 sdetails
#100.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails
#140.00 sdetails
#150.00 sdetails
#160.00 sdetails
#170.00 sdetails
#180.06 sdetails
#190.00 sdetails
#200.00 sdetails
#210.00 sdetails
#220.00 sdetails
#23ACCEPTED0.04 sdetails

Code

import sys
inp = sys.stdin.read().split()

n = int(inp[0])


if n <3 :
    print("IMPOSSIBLE")
    exit()


x = int(inp[1])
ind=0
numbers = []
for i in inp[2:]:
    numbers.append((int(i),ind))
    ind+=1


snumbers = sorted(numbers,key=lambda x: x[0])
#snumbers = sorted([item for item in numbers if item[0] <x-1],key=lambda x: x[0],reverse=True)

#let's start with a naive approach
    
left = 0
#middle = n//2
right = n-1


while(left<right):
    print(left,right)
    if snumbers[left][0] + snumbers[right][0] >=x :
        right -=1
    else :
        l = left
        r = right
        while(l<=r):
            mid = l + (r - l) //2
            total = snumbers[mid][0] + snumbers[left][0] + snumbers[right][0] 
            print(f"total is {total} with {l,mid,r}")
            if total == x:
                print(left,mid,right)
                exit()
            elif total < x:
                l = mid+1
            else:
                r = mid-1
        l+=1
print("IMPOSSIBLE")
#print(ind)
'''
while(left<right):
    print(left,right)
    total = snumbers[left][0] + snumbers[middle][0] + snumbers[right][0]
    print(total)
    if total == x :
        print(f"{left} {middle} {right}")
        exit()
    elif total >x :
        right -=1
    else :
        #do binary earch between them
'''

Test details

Test 1

Verdict: ACCEPTED

input
1 3
1

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 2

Verdict:

input
3 5
1 3 2

correct output
IMPOSSIBLE

user output
0 2
total is 6 with (0, 1, 2)
total is 5 with (0, 0, 0)
0 0 2

Test 3

Verdict:

input
3 6
1 3 2

correct output
1 3 2

user output
0 2
total is 6 with (0, 1, 2)
0 1 2

Test 4

Verdict:

input
3 7
3 2 1

correct output
IMPOSSIBLE

user output
0 2
total is 6 with (0, 1, 2)
total is 7 with (2, 2, 2)
0 2 2

Test 5

Verdict:

input
7 3
2 1 1 2 2 1 1

correct output
2 3 7

user output
0 6
0 5
0 4
0 3
total is 3 with (0, 1, 3)
...

Test 6

Verdict:

input
7 4
1 1 2 2 1 2 1

correct output
1 2 6

user output
0 6
total is 4 with (0, 3, 6)
0 3 6

Test 7

Verdict:

input
7 5
1 2 1 2 2 1 1

correct output
1 2 5

user output
0 6
total is 4 with (0, 3, 6)
total is 5 with (4, 5, 6)
0 5 6

Test 8

Verdict:

input
7 6
2 1 1 1 1 2 2

correct output
1 6 7

user output
(empty)

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
0 4999
total is 3 with (0, 2499, 4999...

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

Test 12

Verdict:

input
5000 919900245
663612758 9075403 585385629 98...

correct output
2787 465 2266

user output
(empty)

Test 13

Verdict:

input
5000 999989608
12983 25966 38949 51932 64915 ...

correct output
IMPOSSIBLE

user output
(empty)

Test 14

Verdict:

input
5000 1000000000
65536 131072 196608 262144 327...

correct output
IMPOSSIBLE

user output
(empty)

Test 15

Verdict:

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

correct output
IMPOSSIBLE

user output
(empty)

Test 16

Verdict:

input
5000 919900246
663612758 9075403 585385629 98...

correct output
193 1698 4019

user output
(empty)

Test 17

Verdict:

input
5000 919900247
663612758 9075403 585385629 98...

correct output
4258 470 1911

user output
(empty)

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
0 4999
0 4998
0 4997
0 4996
0 4995
...

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

Test 20

Verdict:

input
4999 919900245
9075403 585385629 987230075 83...

correct output
2786 464 2265

user output
(empty)

Test 21

Verdict:

input
5000 1000000000
261323261 25262018 237798562 3...

correct output
IMPOSSIBLE

user output
(empty)

Test 22

Verdict:

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

correct output
IMPOSSIBLE

user output
(empty)

Test 23

Verdict: ACCEPTED

input
2 6
2 2

correct output
IMPOSSIBLE

user output
IMPOSSIBLE