-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11057.cpp
More file actions
34 lines (31 loc) · 732 Bytes
/
Copy path11057.cpp
File metadata and controls
34 lines (31 loc) · 732 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
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#define foi( i , n , k ) for( int i = n ; i <k ; ++i )
using namespace std;
int main()
{
int n;
while( scanf("%d",&n)!=EOF)
{
vector<int> book(n);
foi( i , 0 , n )
{
scanf("%d",&book[i]);
}
sort( book.begin() , book.end() );
int p;
scanf("%d",&p);
pair<int,int> may(0,9999999);
foi( i , 0 , n )
{
if( p>book[i] && binary_search(book.begin()+i,book.end(),p-book[i]) )
{
may=((may.second-may.first)<((p-book[i])-book[i]))?may:make_pair(book[i],(p-book[i]));
}
}
printf("Peter should buy books whose prices are %d and %d.\n\n",may.first,may.second);
}
return 0;
}