| Task: | 3SUM |
| Sender: | aalto26gm_049 |
| Submission time: | 2026-10-19 17:41:22 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | RUNTIME ERROR |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.05 s | details |
| #2 | RUNTIME ERROR | 0.05 s | details |
| #3 | RUNTIME ERROR | 0.05 s | details |
| #4 | RUNTIME ERROR | 0.05 s | details |
| #5 | RUNTIME ERROR | 0.05 s | details |
| #6 | RUNTIME ERROR | 0.05 s | details |
| #7 | RUNTIME ERROR | 0.05 s | details |
| #8 | RUNTIME ERROR | 0.05 s | details |
| #9 | RUNTIME ERROR | 0.08 s | details |
| #10 | RUNTIME ERROR | 0.08 s | details |
| #11 | RUNTIME ERROR | 0.08 s | details |
| #12 | RUNTIME ERROR | 0.10 s | details |
| #13 | RUNTIME ERROR | 0.09 s | details |
| #14 | RUNTIME ERROR | 0.09 s | details |
| #15 | RUNTIME ERROR | 0.08 s | details |
| #16 | RUNTIME ERROR | 0.10 s | details |
| #17 | RUNTIME ERROR | 0.09 s | details |
| #18 | RUNTIME ERROR | 0.07 s | details |
| #19 | RUNTIME ERROR | 0.07 s | details |
| #20 | RUNTIME ERROR | 0.09 s | details |
| #21 | RUNTIME ERROR | 0.09 s | details |
| #22 | RUNTIME ERROR | 0.09 s | details |
| #23 | ACCEPTED | 0.05 s | details |
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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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: RUNTIME ERROR
| 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 |
