7 条题解

  • 1
    @ 2023-5-2 18:18:43
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n,m,a[1000005];
    bool check(int h)
    {
    	int sum = 0;
    	for(int i = 1;i <= n;i++)
    		if(a[i] > h)
    			sum += (a[i]-h);
    	return sum >= m;
    }
    int main()
    {
    	cin >> n >> m;
    	for(int i = 1;i <= n;i++) cin >> a[i];
    	int l = 0,r = 1000000000;
    	while(l < r)
    	{
    		int mid = (l + r + 1) >> 1;
    		if(check(mid)) l = mid;
    		else r = mid - 1;
    	}
    	cout << l;
    	return 0;
    }
    
    
    • 0
      @ 2024-11-3 15:43:54

      #include<iostream> #include<algorithm> using namespace std; long long a[1000005]; long long n,m,ans; bool check(int x) { int sum = 0; for(int i = 1;i <= n;i++) { if(a[i] > x) sum += a[i] - x; } return sum >= m; } int main() { cin >> n >> m; for(int i = 1;i <= n;i++) { cin >> a[i]; } sort(a + 1,a + n + 1); long long l = 0,r = a[n]; while(l <= r) { int mid = (l + r) / 2; if(check(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << endl; return 0; }

      • 0
        @ 2023-5-1 11:46:05
        #include<algorithm>
        using namespace std;
        int a[1000005],n,m;  
        bool check(int h){
        	int sum=0;
        	for (int i=1; i<=n; i++){
        		if (a[i]>h){
        			sum += (a[i]-h);
        		}
        	
        	}
        	return sum>=m;
        }                                                
        int main(){
        	cin >>n >> m;
        	for (int i=1; i<=n; i++){
        		cin >> a[i];
        	}
        	int l=0,r=1000000000;
        	while(l<r){
        		int mid=(l+r+1)>>1;
        		if (check(mid)) {
        			l=mid;
        		}
        		else {
        			r=mid-1;
        		}
        	}
        	cout << l;
        	return 0;
        }
        
        
        • -1
          @ 2023-4-23 13:47:53
          #include <bits/stdc++.h>
          
          using namespace std;
          typedef long long ll;
          const int N = 1000010;
          ll a[N];
          ll n, m;
          
          ll check(ll x) {
          	ll sum = 0;
          	for (int i = 0; i < n; i++) {
          		if (a[i] > x) {
          			sum += (a[i] - x);
          			if (sum >= m) return true;
          		}
          	}
          	return false;
          }
          
          int main() {
          	// freopen("in.txt", "r", stdin);
          	cin >> n >> m;
          	for (int i = 0; i < n; i++) scanf("%lld", a + i);
          	ll l = 0, r = 0;
          	for (int i = 0; i < n; i++) r = max(r, a[i]);
          	 //for (int i = l; i <= r; i++) cout << i << " " << check(i) << endl;
          	while (l < r) {
          		ll mid = l + r + 1 >> 1;
          		if (check(mid)) l = mid;
          		else r = mid - 1;
          	}
          	printf("%lld", l);
          	return 0;
          }
          
          
          • -2
            @ 2024-11-3 15:46:04
            #include<iostream>
            #include<algorithm>
            using namespace std;
            int n,m,a[1114514];
            bool check(int h)
            {
            	int sum = 0;
            	for(int i = 1;i <= n;i++)
            		if(a[i] > h)
            			sum += (a[i]-h);
            	return sum >= m;
            }
            int main()
            {
            	cin >> n >> m;
            	for(int i = 1;i <= n;i++) cin >> a[i];
            	int l = 0,r = 1000000000;
            	while(l < r)
            	{
            		int mid = (l + r + 1) >> 1;
            		if(check(mid)) l = mid;
            		else r = mid - 1;
            	}
            	cout << l;
            	return 0;
            }
            
            • -2
              @ 2022-10-15 16:43:17

              cout << "293"

              • -4
                @ 2024-12-17 16:38:32
                #include<bits/stdc++.h>
                using namespace std;
                const int N=1e7+10;
                int sum,ans,num;
                int a[N],n,r;
                int main(){
                	cin>>n>>r;
                    for(int i=1;i<=n;i++){
                    	cin>>a[i];
                	}
                    sort(a+1,a+n+1);
                    num=n;
                    while(sum<r){
                        sum+=(a[num]-a[num-1])*(n-num+1);
                        num--;
                    }
                    num++;
                    ans=a[num-1]+(sum-r)/(n-num+1);
                    cout<<ans;
                    return 0;
                }
                小鸟
                
                • @ 2024-12-17 16:41:05

                  飞舞

                • @ 2024-12-17 16:41:19

                  没小鸟

                • @ 2024-12-17 16:42:02
                  /*没小鸟的钟鼎皓盗我号骗分*/
                  /*小心slz钟鼎皓 药哥嗑药抄题解不改头文件!!!!!!!!!!!!!!!!!!!!!!!!!!*/
                  #include <bits/stdc++.h>
                  #define LL long long
                  using namespace std;
                  const int N = 1e6 + 10;
                  const int INF = 0x3f3f3f3f;
                  int n , m , l , r , ans;
                  int a [N];
                  bool check (int mid)
                  {
                  	int sum = 0;
                  	for (int i = 1; i <= n; i++)
                  	{
                  		if (a [i] > mid)
                  		{
                  			sum += a [i] - mid;
                  		}
                  	}
                  	return (sum >= m);
                  }
                  int main()
                  {
                  	    cin >> n >> m;
                  		for (int i = 1; i <= n; i++)
                  	    {
                  	    	cin >> a [i];
                  		}
                  		sort (a + 1 , a + 1 + n); 
                  		l = 1;
                  		r = a [n];
                  		while (l <= r)
                  		{
                  			int mid = (l + r) >> 1;
                  			if (check (mid))
                  			{
                  				ans = mid;
                  				l = mid + 1;
                  			}
                  			else 
                  			    r = mid - 1;
                  		} 
                  		cout << ans;
                  		return 0;
                  }
                  /*小心slz钟鼎皓或 上线盗你号 没小鸟的钟鼎皓盗我号骗分
                  
                  */
                  
              • 1

              信息

              ID
              1280
              时间
              1000ms
              内存
              256MiB
              难度
              7
              标签
              递交数
              496
              已通过
              128
              上传者