Submission details
Task:3SUM
Sender:aalto26gm_049
Submission time:2026-10-19 17:27:18 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#10.05 sdetails
#2ACCEPTED0.05 sdetails
#30.05 sdetails
#4ACCEPTED0.05 sdetails
#50.10 sdetails
#60.05 sdetails
#70.05 sdetails
#80.10 sdetails
#90.08 sdetails
#10ACCEPTED0.12 sdetails
#110.17 sdetails
#120.15 sdetails
#13ACCEPTED0.13 sdetails
#14ACCEPTED0.14 sdetails
#15ACCEPTED0.14 sdetails
#160.14 sdetails
#170.15 sdetails
#180.11 sdetails
#19ACCEPTED0.12 sdetails
#200.14 sdetails
#21ACCEPTED0.14 sdetails
#22ACCEPTED0.15 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+1];

        for (int i = 1; i <= n; i++){
            int temp = input.nextInt();
            if (temp > x - 2) {
                numbers[i] = 0;
            } else{
                numbers[i] = temp;
            }
        }
        int[] sorted = numbers;
        Arrays.sort(sorted);

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

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

        }
        i = i-1;

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

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

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

            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:

input
1 3
1

correct output
IMPOSSIBLE

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 2
	at ThreeSum.main(ThreeSum.java:53)

Test 2

Verdict: ACCEPTED

input
3 5
1 3 2

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 3

Verdict:

input
3 6
1 3 2

correct output
1 3 2

user output
IMPOSSIBLE

Test 4

Verdict: ACCEPTED

input
3 7
3 2 1

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 5

Verdict:

input
7 3
2 1 1 2 2 1 1

correct output
2 3 7

user output
1 4 5

Test 6

Verdict:

input
7 4
1 1 2 2 1 2 1

correct output
1 2 6

user output
IMPOSSIBLE

Test 7

Verdict:

input
7 5
1 2 1 2 2 1 1

correct output
1 2 5

user output
IMPOSSIBLE

Test 8

Verdict:

input
7 6
2 1 1 1 1 2 2

correct output
1 6 7

user output
1 5 6

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
IMPOSSIBLE

Test 10

Verdict: ACCEPTED

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

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

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 4998 4999

Test 12

Verdict:

input
5000 919900245
663612758 9075403 585385629 98...

correct output
2787 465 2266

user output
422 482 4893

Test 13

Verdict: ACCEPTED

input
5000 999989608
12983 25966 38949 51932 64915 ...

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 14

Verdict: ACCEPTED

input
5000 1000000000
65536 131072 196608 262144 327...

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 15

Verdict: ACCEPTED

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

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 16

Verdict:

input
5000 919900246
663612758 9075403 585385629 98...

correct output
193 1698 4019

user output
427 454 4925

Test 17

Verdict:

input
5000 919900247
663612758 9075403 585385629 98...

correct output
4258 470 1911

user output
529 2039 3234

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
1 4999 5000

Test 19

Verdict: ACCEPTED

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

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 20

Verdict:

input
4999 919900245
9075403 585385629 987230075 83...

correct output
2786 464 2265

user output
422 482 4892

Test 21

Verdict: ACCEPTED

input
5000 1000000000
261323261 25262018 237798562 3...

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 22

Verdict: ACCEPTED

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

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 23

Verdict: ACCEPTED

input
2 6
2 2

correct output
IMPOSSIBLE

user output
IMPOSSIBLE