Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- int main()
- {
- for(int n; ~scanf("%d", &n);)
- {
- int arr[n], m, a, b;
- for(int i=0; i<n; i++)
- scanf("%d", arr+i);
- scanf("%d", &m);
- sort(arr, arr+n);
- for(int i=0; arr[i]*2<=m && i<n; i++)
- {
- int tmp=*lower_bound(arr+i+1, arr+n, m-arr[i]);
- if(tmp==m-arr[i])
- a=arr[i], b=tmp;
- }
- printf("Peter should buy books whose prices are %d and %d.\n\n", a, b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement