-
Notifications
You must be signed in to change notification settings - Fork 9
/
sumoftwovalues.java
40 lines (36 loc) · 1007 Bytes
/
sumoftwovalues.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.HashMap;
import java.util.Scanner;
/**
* sumoftwovalues
*/
public class sumoftwovalues {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int target = s.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = s.nextInt();
}
HashMap<Integer, Integer> map = new HashMap();
int[] positions = new int[2];
boolean flag = false;
for (int i = 0; i < n; i++){
Integer val = map.get(target - a[i]);
if(val == null){
map.put(a[i], i);
} else {
positions[0] = val + 1;
positions[1] = i + 1;
flag = !flag;
break;
}
}
if(flag){
System.out.println(positions[0] + " " + positions[1]);
} else {
System.out.println("IMPOSSIBLE");
}
s.close();
}
}