-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUVa 11057.cpp
57 lines (40 loc) · 891 Bytes
/
UVa 11057.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define iter(i,a,b) for(int i = (a) ; i < (b) ; i++)
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> iii;
typedef vector <pii> vii;
#define INF 1000000000
#define MAXX 1000
int main(){
//READ("UVa 11057.txt");
int n, m;
while(scanf("%d", &n) != EOF){
int b[n];
rep(i, n)
scanf("%d", &b[i]);
sort(b, b + n);
scanf("%d", &m);
int i = 0, j = n - 1;
int res_i, res_j;
while(i < j){
if(b[i] + b[j] < m)
i++;
else if(b[i] + b[j] == m){
res_i = i;
res_j = j;
i++;
j--;
}
else
j--;
}
printf("Peter should buy books whose prices are %d and %d.\n\n", b[res_i], b[res_j]);
}
return 0;
}