Advertisement
gabrielcabezas

Untitled

Apr 16th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long double hi=1e14+5;
  6. long double lo=0;
  7. int n,area,i,soma,v[150000];
  8. while (1)
  9. {
  10. hi=1e14+5;
  11. lo=0-1e-9;
  12. soma=0;
  13. scanf("%d %d",&n,&area);
  14. if (n==0 && area==0)break;
  15. for (i=0; i<n; i++)
  16. {
  17. scanf("%d",&v[i]);
  18. soma+=v[i];
  19. }
  20. if (soma==area)
  21. printf(":D\n");
  22.  
  23. else
  24. {
  25. if (soma<area)
  26. printf("-.-\n");
  27. else
  28. {
  29. long double md;
  30. while (1)
  31. {
  32. md=(hi+lo)/2;
  33. for (int i=0;i<n;i++)
  34. {
  35. if (md < v[i])
  36. v[i]-=md;
  37. }
  38. soma=0;
  39. for (int i=0;i<n;i++)
  40. {
  41. soma+=v[i];
  42. }
  43. if (soma - area > 1e-4 )
  44. lo=md;
  45. else if (area-soma > 1e-4)
  46. hi=md;
  47. else if (area - soma <=1e-4 || soma - area<= 1e-4 )
  48. break;
  49. }
  50. cout << lo << endl;
  51. }
  52. }
  53. }
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement