-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva 11057.cpp
59 lines (47 loc) · 995 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
58
59
#include<iostream>
#include<cstdio>
#define pf printf
using namespace std;
long long a[100000];
int main()
{
long long n,i,j,d,m;
long long sn,bn;
while(cin>>n)
{
d=1200000;
for(i=0; i<n; i++)
{
cin>>a[i];
}
cin>>m;
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(a[i]+a[j]==m && i!=j)
{
if(a[i]>a[j])
{
if(a[i]-a[j]<d)
{
sn=a[j];
bn=a[i];
d= a[i]-a[j];
}
}
else{
if(a[j]-a[i]<d)
{
sn=a[i];
bn=a[j];
d= a[j]-a[i];
}
}
}
}
}
pf("Peter should buy books whose prices are %lld and %lld.\n\n",sn,bn);
}
return 0;
}