Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 786 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 468 |

@Rahul Jadhav 1 | 466 |

Complete Leaderboard |

You are given an array **A** of size **N**. You need to find **all pairs** in the array that sum to a number **K**. If no such pair exists then output will be **-1**. The elements of the array are **distinct **and are in **sorted **order.

**Note:** (a,b) and (b,a) are considered same. Also, an element cannot pair with itself, i.e., (a,a) is invalid.

**Input:**

The first line of input is **T** denoting the number of testcase. **T** testcases follow. Each testcase contains **three **lines of input. The first line is the size of array N. The second line contains N elements separated by spaces. The third line contains the sum K.

**Output:**

For each testcase, print all the pairs such that there sum is equal to K.

**Constraints:**

1 <= T <= 100

0 <= A_{i} <=10^{7}

2 <= N <= 10^{7}

0 <= K <= 10^{7}

**Examples:**

**Input:**

2

7

1 2 3 4 5 6 7

98

7

1 2 3 4 5 6 7

8

**Output:**

-1

1 7 8

2 6 8

3 5 8

**Explanation:
Testcase1: **We cannot find any pair that sums to 98

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Pair with given sum in a sorted array

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.