Codeforces Round #202 c-mafia__ Two-point search

Source: Internet
Author: User

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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.