Advertisement
Saleh127

uva 11057

Jun 27th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. int main()
  7. {
  8. fellow_junior
  9.  
  10. int a[100000],c,d,e,f,i,j,k,l,x;
  11. while(cin>>c)
  12. {
  13. for(i=0;i<c;i++)
  14. {
  15. cin>>a[i];
  16. }
  17. cin>>d;
  18. sort(a,a+c);
  19. k=1e9;
  20. for(i=0;i<c;i++)
  21. {
  22. for(j=i;j<c;j++)
  23. {
  24. e=abs(a[j]-a[i]);
  25. x=a[i]+a[j];
  26. if(x==d && e<k)
  27. {
  28. f=a[i];
  29. l=a[j];
  30. k=e;
  31. }
  32. }
  33. }
  34. printf("Peter should buy books whose prices are %d and %d.\n",f,l);
  35. printf("\n");
  36. }
  37.  
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement