Advertisement
kcku

11057 - Exact Sum

Jul 10th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     for(int n; ~scanf("%d", &n);)
  8.     {
  9.         int arr[n], m, a, b;
  10.  
  11.         for(int i=0; i<n; i++)
  12.             scanf("%d", arr+i);
  13.  
  14.         scanf("%d", &m);
  15.         sort(arr, arr+n);
  16.  
  17.         for(int i=0; arr[i]*2<=m && i<n; i++)
  18.         {
  19.             int tmp=*lower_bound(arr+i+1, arr+n, m-arr[i]);
  20.  
  21.             if(tmp==m-arr[i])
  22.                 a=arr[i], b=tmp;
  23.         }
  24.         printf("Peter should buy books whose prices are %d and %d.\n\n", a, b);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement