51Nod 1001 pairs of numbers equal to K in arrays

Source: Internet
Author: User

1001 number pairs in array and equal to K

Base time limit: 1 seconds space limit: 131072 KB score: 5 difficulty: 1-level algorithm problem

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)

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

-1

6

5

3

4

2

9

0

8

Output example

-1 9

0 8

2 6

3 5

Violence never thought it would.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 intn;7 Long Longa[50010],k;8 intMain ()9 {Tenscanf"%lld%d",&k,&n); one     BOOLtemp=false; a      for(intI=1; i<=n;i++) -scanf"%lld",&a[i]); -Sort (a +1, a+n+1); the      for(intI=1; i<=n;i++){ -         if((a[i]+a[n]) <k)Continue; -          for(intj=i+1; j<=n&&a[i]+a[j]<=k;j++){ -             if(a[i]+a[j]==k) { +temp=true; -printf"%lld%lld\n", a[i],a[j]); +             } a         } at     } -     if(!temp) printf ("No solution\n"); -     return 0; -}

1001 The sum of the numbers in a group equals K the number of pairs

< Span style= "font-size:7.5pt; font-family: Microsoft Jacob black, sans-serif; > base time Limit: 1 , Second space limit: 131072 kb score :  5  difficulty: 1 class algorithm questions

Given an integer K and an unordered array a, the elements ofa are N distinct integers, and the pairs of all and equal K in array a are found. For example K = 8, array A:{ -1,6,5,3,4,2,9,0,8}, all and equal to 8 pairs including ( -1,9),(0,8) ,(2,6),(3,5).

Input

Line 1 : 2 number separated by a space,K n,n is the length of a array. (2 <= N <= 50000,-10^9 <= K <= 10^9)

2-n + 1 rows: N elements ofa array. (-10^9 <= a[i] <= 10^9)

Output

Line 1-m : 2 per line, requires a smaller number in front, and the M number is in ascending order of a smaller number.

If there is no one set of solutions output: nosolution.

Input Example

8 9

-1

6

5

3

4

2

9

0

8

Output Example

-1 9

0 8

2 6

3 5

51Nod 1001 pairs of numbers equal to K in arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.