Submission details
Task:3SUM
Sender:aalto26gm_049
Submission time:2026-10-19 17:41:22 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#20.05 sdetails
#30.05 sdetails
#40.05 sdetails
#50.05 sdetails
#60.05 sdetails
#70.05 sdetails
#80.05 sdetails
#90.08 sdetails
#100.08 sdetails
#110.08 sdetails
#120.10 sdetails
#130.09 sdetails
#140.09 sdetails
#150.08 sdetails
#160.10 sdetails
#170.09 sdetails
#180.07 sdetails
#190.07 sdetails
#200.09 sdetails
#210.09 sdetails
#220.09 sdetails
#23ACCEPTED0.05 sdetails

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class ThreeSum {
    public static void main(String[] args) {
        FastScanner input = new FastScanner(System.in);
        int n = input.nextInt();
        int x = input.nextInt();

        int[] numbers = new int[n];

        for (int i = 0; i < n; i++){
            numbers[i] = input.nextInt();
        }
        int[] sorted = numbers.clone();
        Arrays.sort(sorted);

        int i = 0;
        int j = 0;
        int k = 0;

        Boolean found = false;
        while(i < n-2 && !found){

            j = i+1;
            k =n;
            while (k > j && !found && j<n){
                if (sorted[i] + sorted[j] + sorted[k] > x) {
                    k--;
                } else if (sorted[i] + sorted[j] + sorted[k] < x){
                    j++;
                } else {
                    found = true;
                    i--;
                }
            }
            i++;
        }


            int a = sorted[i];
            int b = sorted[j];
            int c = sorted[k];

            int aI = 0;
            int bI = 0;
            int cI = 0;

            for (int y = 0; y < n; y++){
                if(numbers[y] == a && aI == 0){
                    aI = y+1;
                } else if (numbers[y] == b && bI == 0){
                    bI = y+1;
                } else if (numbers[y] == c && cI == 0){
                    cI = y +1;
                }
            }

            if (!found || aI == 0|| bI == 0|| cI == 0){
                System.out.println("IMPOSSIBLE");
            }else {
                System.out.println(aI + " " + bI + " " + cI);
            }


    }

    static class FastScanner { //static class fastScanner
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
    	 return Double.parseDouble(next());
	 }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}
}

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

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
	at ThreeSum.main(ThreeSum.java:32)

Test 3

Verdict:

input
3 6
1 3 2

correct output
1 3 2

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
	at ThreeSum.main(ThreeSum.java:32)

Test 4

Verdict:

input
3 7
3 2 1

correct output
IMPOSSIBLE

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
	at ThreeSum.main(ThreeSum.java:32)

Test 5

Verdict:

input
7 3
2 1 1 2 2 1 1

correct output
2 3 7

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 7
	at ThreeSum.main(ThreeSum.java:32)

Test 6

Verdict:

input
7 4
1 1 2 2 1 2 1

correct output
1 2 6

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 7
	at ThreeSum.main(ThreeSum.java:32)

Test 7

Verdict:

input
7 5
1 2 1 2 2 1 1

correct output
1 2 5

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 7
	at ThreeSum.main(ThreeSum.java:32)

Test 8

Verdict:

input
7 6
2 1 1 1 1 2 2

correct output
1 6 7

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 7
	at ThreeSum.main(ThreeSum.java:32)

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

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

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)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

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)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 12

Verdict:

input
5000 919900245
663612758 9075403 585385629 98...

correct output
2787 465 2266

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 13

Verdict:

input
5000 999989608
12983 25966 38949 51932 64915 ...

correct output
IMPOSSIBLE

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 14

Verdict:

input
5000 1000000000
65536 131072 196608 262144 327...

correct output
IMPOSSIBLE

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 15

Verdict:

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

correct output
IMPOSSIBLE

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 16

Verdict:

input
5000 919900246
663612758 9075403 585385629 98...

correct output
193 1698 4019

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 17

Verdict:

input
5000 919900247
663612758 9075403 585385629 98...

correct output
4258 470 1911

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

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

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

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)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 20

Verdict:

input
4999 919900245
9075403 585385629 987230075 83...

correct output
2786 464 2265

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4999 out of bounds for length 4999
	at ThreeSum.main(ThreeSum.java:32)

Test 21

Verdict:

input
5000 1000000000
261323261 25262018 237798562 3...

correct output
IMPOSSIBLE

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 22

Verdict:

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

correct output
IMPOSSIBLE

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5000 out of bounds for length 5000
	at ThreeSum.main(ThreeSum.java:32)

Test 23

Verdict: ACCEPTED

input
2 6
2 2

correct output
IMPOSSIBLE

user output
IMPOSSIBLE