The second part of the question, for the determination of the X update, we can determine whether it can be updated, if the arbitrary a[i]<x &&∑ (X-a[i]) >=x to meet the situation. For x, the bigger the X, the faster it gets everyone to update it, so that there is a monotony, and you can do it in two points. This problem also did not think of two points to do, do the problem to consider a number of ways to solve problems. At the mean or the problem brush not enough, understand not deep.
/*if I Get TLE and it is good. If I get Ac,it's nice!*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxn=1e6+100;
ll A[MAXN];
ll N;
ll judge (ll X)
{
ll sum=0;
for (ll i=1;i<=n;i++)
{
if (a[i]<=x) sum+=x-a[i];
else return 0;
}
if (sum<x) return 0;
return 1;
}
int main (void)
{
cin >> N;
for (int i=1;i<=n;i++)
scanf ("%d", &a[i]);
ll Left=1,right=1e14,mid;
ll ans;
while (left <= right)
{
mid=left+ (right-left)/2;
if (judge (mid)) ans=mid,right=mid-1; For the feasible mid, we go to the left side of the range to find a small possible point and save
else left=mid+1;
printf ("%i64d-%i64d-%i64d\n", Left,right,mid);
}
printf ("%i64d\n", Judge (3));
printf ("%i64d\n", ans);
}