Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <cstdio>
- #include <stdlib.h>
- #include <string.h>
- #include <vector>
- #include <vector>
- #include <algorithm>
- #include <sstream>
- #include <math.h>
- #include <set>
- #include <map>
- #include <iomanip>
- #define pb push_back
- #define mp make_pair
- #define F first
- #define S second
- #define ll long long
- #define ull unsigned long long
- #define PI 3.14159265359
- #define INF 400000.0
- #define pll pair<long, long>
- using namespace std;
- ll a[100500],ans=0;
- ll n,k;
- void bs(ll l,ll r){
- while(l<=r){
- ll m=(l+r)/2;
- bool ok=false;
- ll need=0;
- for(int i=0;i<n;i++){
- if(a[i]<m) need+=m-a[i];
- }
- if(need<=k) ok=true;
- if(!ok){
- r=m-1;
- } else{
- ans=max(ans,m);
- l=m+1;
- }
- }
- }
- int main()
- {
- freopen("repair.in", "r", stdin);
- freopen("repair.out", "w", stdout);
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin>>n>>k;
- for(int i=0;i<n;i++){
- cin>>a[i];
- }
- bs(0,1000000000*(ll)100500);
- cout<<ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement