Given an integer k and an unordered array, the elements of a,a are n distinct integers, finding the pairs of all and equal k in array a. For example k = 8, Array a:{-1,6,5,3,4,2,9,0,8}, all and equal to 8 pairs include ( -1,9), (0,8), (2,6), (3,5). Input
Line 1th: 2 numbers separated by a space, K n,n is the length of a array. (2 <= n <= 50000,-10^9 <= K <= 10^9) Section 2-n + 1 rows: N elements of a array. ( -10^9 <= a[i] <= 10^9)
Output
Line 1-m: 2 numbers per line, requires a smaller number in front, and the m number is in ascending order of smaller numbers. If there is no one set of solutions output: no solution.
Input example
8 9-165342908
Output example
-1 90 82 63 5
Set or two points, water problem.
1#include <iostream>2#include <stdio.h>3#include <algorithm>4#include <Set>5 using namespacestd;6 Const intMAX =50010;7 intA[max], K, N;8 Set<int>St, st1;9 Ten intMain () { OneCin>>k>>N; A for(inti =1; I <= N; i + +) scanf ("%d",&A[i]), St.insert (A[i]); -Sort (A +1, A +1+n); - intAns =0; the for(inti =1; I <= N; i + +) { - intx = k-A[i]; - if(St.count (x) && x! = A[i] &&!St1.count (x)) -printf"%d%d\n", A[i], x), St1.insert (A[i]), St1.insert (x), ans++; + } - if(ans = =0) +printf"No solution\n"); A return 0; at}
51nod 1001 pairs of numbers equal to K in arrays