-
Notifications
You must be signed in to change notification settings - Fork 0
/
11057.cpp
47 lines (40 loc) · 778 Bytes
/
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
#include<iostream>
#include<algorithm>
#include<vector>
#include<iterator>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
vector<int>::iterator it1,it2,it3;
int n,m,a,f;
while(cin>>n)
{
vector<int>v(n);
for(int i=0;i<n;i++) cin>>v[i];
cin>>m;
sort(v.begin(),v.end());
it1=lower_bound(v.begin(),v.end(),m/2);
if(*it1==m/2) it1=it1;
else if(it1!=v.begin()) it1--;
it2=it1+1;
f=0;
while(it1!=v.begin())
{
it3=find(it2,v.end(),m-*it1);
if(it3!=v.end())
{
f=1;
cout<<"Peter should buy books whose prices are "<<*it1<<" and "<<*it3<<".\n\n";
break;
}
it1--;
}
if(!f)
{
cout<<"Peter should buy books whose prices are "<<*it1<<" and "<<m-*it1<<".\n\n";
}
}
return 0;
}