1 solutions

  • 2
    @ 2024-2-29 13:39:30
    #include<iostream>
    #define int unsigned long long
    using namespace std;
    int n,c,a[11451400];
    bool check(int m)
    {
    	int sum=0;
    	for(int i=0;i<n;i++)
    	{
    		sum+=(a[i]+2*m)*(a[i]+2*m);//每块纸板的面积
    	}
    	return sum>c;//注意是返回什么
    }
    signed main()//因为用了define
    {
    	int t;
    	cin>>t;//输入
    	for(int ti=0;ti<t;ti++)
    	{
    		cin>>n>>c;//输入
    		for(int i=0;i<n;i++)
    		{
    			cin>>a[i];//输入
    		}
    		int l=0,m,r=1000000000;
    		while(l<=r)//边界
    		{
    			m=(l+r)/2;//分半
    			if(check(m))//大了返回true
    			{
    				r=m-1;//缩半
    			}
    			else
    			{
    				l=m+1;//缩半
    			}
    		}
    		cout<<r<<endl;//输出
    	}
    	return 0;//完结散花
    }
    
    • @ 2024-3-1 13:12:59

      一定要 unsigned long long!不然不能全 AC

  • 1

Information

ID
916
Time
1000ms
Memory
256MiB
Difficulty
7
Tags
(None)
# Submissions
56
Accepted
12
Uploaded By