Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define ST first
- #define ND second
- typedef pair<int,int> PII;
- #define REP(i,n) for(int i=0;i<(n);i++)
- int A[10010];
- int main () {
- int n;
- while(scanf("%d",&n) == 1) {
- REP(i,n) scanf("%d",&A[i]);
- int m;
- scanf("%d",&m);
- sort(A,A+n);
- int aux = 1<<30;
- PII sol;
- REP(i,n) {
- bool b = binary_search(A+i+1,A+n,m-A[i]);
- if(b) {
- int pos = lower_bound(A+i+1,A+n,m-A[i])-A;
- if(abs(A[pos] - A[i]) < aux) {
- aux = A[pos]-A[i];
- sol.ST = A[i]; sol.ND = A[pos];
- }
- }
- }
- printf("Peter should buy books whose prices are %d and %d.\n\n",sol.ST,sol.ND);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement