HackerRank: Ice Cream Parlor
Sunny and Johnny together have M dollars and want to spend the amount at an ice cream parlour. The parlour offers N flavors, and they want to choose 2 flavors so that they end up spending the whole amount.
You are given a list of cost of these N flavors. The cost of ith flavor is denoted by (ci). You have to display the indices of two flavors whose sum is M.
https://codepair.hackerrank.com/paper/WwupEu0i?b=eyJyb2xlIjoiY2FuZGlkYXRlIiwibmFtZSI6ImplZmZlcnl5dWFuIiwiZW1haWwiOiJ5dWFueXVuLmtlbm55QGdtYWlsLmNvbSJ9
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int k = 0; k < n; k++){
int C = sc.nextInt();
int P = sc.nextInt();
int [] p = new int[P+1];
for(int i = 1; i <= P;i++)p[i] = sc.nextInt();
for(int i = 1; i <= P; i++){
for(int j = i+1; j <= P; j++){
if(p[i]+p[j] == C){
System.out.println(i + " " + j);
break;
}
}
}
}
sc.close();
}