钛蒻了。。。二分写炸了。。。但惊奇的是TLE,并没WA
思想是二分最小员工数,check()就是判断这个数能不能由各部员工加出来。
然后。。。就没有然后了
code:
#include<bits/stdc++.h>
using namespace std;
const int maxn=25;
const int maxr=2e9;
int arr[maxn];
bool check(int num,int n)
{
int res=0;
for(int i=1;i<=n;i++)
{
if(res+arr[i]>num)return false;
if(res+arr[i]==num)return true;
}
return false;
}
int main()
{
int n=0,res=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>arr[i];
}
sort(arr+1,arr+n+1);
int l=1;
int r=maxr;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid,n)==true)
{
res=mid;
r=mid;
}
else
{
l=mid+1;
}
}
cout<<res;
return 0;
}
谢谢各位大佬!