Advertisement
TLE

11057

TLE
Mar 15th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. long c,a[10005],p,i,j,ln,t,tm,mx,f,k,ai,aj,p1,p2;
  6. while( scanf("%ld\n",&c) != EOF)
  7. {
  8. i=0;
  9. for(k=0; k<c; k++)
  10. {
  11. scanf("%ld",&a[i]);
  12. i++;
  13. }
  14. scanf("%ld",&p);
  15. ln = i;
  16. mx = 0;
  17. f = 0;
  18. p1 = 0;
  19. p2 = 0;
  20. for(i=0; i<ln; i++)
  21. {
  22. t = p - a[i];
  23. for(j=i+1; j<ln; j++)
  24. {
  25. if( a[j] == t)
  26. {
  27. ai = a[i];
  28. aj = a[j];
  29. if( ai >= aj)
  30. {
  31. tm = ai;
  32. ai = aj;
  33. aj = tm;
  34. }
  35. if( f == 1)
  36. {
  37. if( mx <= (aj - ai))
  38. {
  39. mx = aj - ai;
  40. continue;
  41. }
  42. }
  43. p1 = ai;
  44. p2 = aj;
  45. mx = aj - ai;
  46. f=1;
  47. }
  48. }
  49. }
  50. printf("Peter should buy books whose prices are %ld and %ld.\n\n",p1,p2);
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement