Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cstdio>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <vector>
  7. #include <vector>
  8. #include <algorithm>
  9. #include <sstream>
  10. #include <math.h>
  11. #include <set>
  12. #include <map>
  13. #include <iomanip>
  14. #define pb push_back
  15. #define mp make_pair
  16. #define F first
  17. #define S second
  18. #define ll long long
  19. #define ull unsigned long long
  20. #define PI 3.14159265359
  21. #define INF 400000.0
  22. #define pll pair<long, long>
  23.  
  24. using namespace std;
  25.  
  26. ll a[100500],ans=0;
  27. ll n,k;
  28.  
  29. void bs(ll l,ll r){
  30. while(l<=r){
  31. ll m=(l+r)/2;
  32. bool ok=false;
  33. ll need=0;
  34. for(int i=0;i<n;i++){
  35. if(a[i]<m) need+=m-a[i];
  36. }
  37. if(need<=k) ok=true;
  38. if(!ok){
  39. r=m-1;
  40. } else{
  41. ans=max(ans,m);
  42. l=m+1;
  43. }
  44. }
  45. }
  46.  
  47. int main()
  48. {
  49. freopen("repair.in", "r", stdin);
  50. freopen("repair.out", "w", stdout);
  51. ios_base::sync_with_stdio(0);
  52. cin.tie(0);
  53. cin>>n>>k;
  54. for(int i=0;i<n;i++){
  55. cin>>a[i];
  56. }
  57. bs(0,1000000000*(ll)100500);
  58. cout<<ans;
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement