-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1001.cpp
More file actions
43 lines (38 loc) · 866 Bytes
/
1001.cpp
File metadata and controls
43 lines (38 loc) · 866 Bytes
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
41
42
43
/*************************************************************************
> File Name: 1001.cpp
> Author: dulun
> Mail: [email protected]
> Created Time: 2015年12月06日 星期日 18时55分31秒
************************************************************************/
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[50008];
int main()
{
int k, n;
cin>>k>>n;
for(int i = 0; i < n; i++) cin>>a[i];
sort(a, a+n);
int flag = 0;
int i = 0, j = n - 1;
while( i < j )
{
if(a[i] + a[j] == k)
{
flag = 1;
cout<<a[i++]<<" "<<a[j--]<<endl;
}
if(a[i] + a[j] < k)
{
i++;
}
if(a[i] + a[j] > k)
{
j--;
}
}
if(flag == 0) cout<<"No Solution"<<endl;
return 0;
}