fork(1) download
  1. #include <iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4. using namespace std;
  5. int main() {
  6. int n;
  7. cin>>n;
  8. for(int i=0;i<n;i++)
  9. {
  10. int a,money=0,n1=0,n2=0;
  11. cin>>a;
  12. int b[a];
  13. for(int j=0;j<a;j++)
  14. cin>>b[j];
  15. cin>>money;
  16. sort(b,b+a);
  17.  
  18.  
  19. for(int j=0;j<a;j++)
  20. {
  21. for(int k=0;k<a;k++)
  22. {
  23. if(b[j]+ b[k]==money && k-j>=0)
  24. { n1=b[j];
  25. n2=b[k];
  26.  
  27. }
  28. }
  29. }
  30.  
  31. int small=0,large=0;
  32. if(n1<=n2)
  33. {
  34. small=n1;
  35. large=n2;
  36.  
  37. }
  38. else if(n1>n2)
  39. {
  40. small=n2;
  41. large=n1;
  42. }
  43. cout<<"Deepak should buy roses whose prices are "<<small<<" and "<<large<<"."<<endl;
  44. }
  45. return 0;
  46. }
  47.  
Time limit exceeded #stdin #stdout 5s 6529024KB
stdin
Standard input is empty
stdout
Standard output is empty