ZCMU — 2154

2154: E.wjw queue problem

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 8   Solved: 5
[ Submit][ Status][ Web Board]

Description

As a study committee member in the class, although wjw is a study committee member, who makes the monitor ly often unreliable? Every time when ly is unreliable, I always need wjw to help her solve the problem... Now it’s near the physical education class, ly got your code but couldn't run it, so she went to find the computer stupidly... But seeing that the class is about to go, the classmates still chat together in twos and threes, wjw has no way, all of a sudden It’s too late to sort everyone by height, so wjw decided to line up everyone as fast as possible. No height is required, as long as everyone doesn’t stand together...
Now the witty wjw everyone abstracts On an X axis, there are many small groups on some integer coordinates of the X axis. The number of the i-th small group is a[i], and the coordinate is b[i].
Now wjw wants to make each of these people stand on an integer coordinate point, and make no two people on the same point.
In order to save time, wjw hopes that the maximum moving distance of each person is the smallest. Please find this minimum

Input

There is only one set of data. The
first row has a positive integer n, indicating how many small groups there are. The
second row has n positive integers a[i], indicating the number of people in the i-th small group. The
third row has n strictly increasing integers b[i ], represents the coordinates of the i-th small group

Output

One non-negative integer per line, which represents the minimum value of the maximum travel distance of each person

Sample Input

2
2 3
0 2

Sample Output

1


[analysis]

Two points of answer and then check, the check method is very simple...All the people with points first move to the left, and then move to the right.

Just make up for the reason. The best way is to spread from the current point x to [x-mid, x+mid]. Then in order to facilitate the movement of the person at the next point, the person at each point must be given priority to the left. Mobile

[Code]

#include <stdio.h>
#define maxn 100001
#define INF 0x7f7f7f7f
int a[maxn], b[maxn];
int n;
int chack(int t)
{
    int l = -INF;
    for (int i = 1; i <= n; i++)
    {
        int xl = b[i] - t, xr = b[i] + t;
        if (l < xl) l = xl;
        if (l + a[i] - 1 > xr) return 0;
        l += a[i];
    }
    return 1;
}
int main()
{
    //freopen("5.in", "r", stdin);
    //freopen("5.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    int l = -1, r = INF;
    while (l + 1 < r)
    {
        int m = (l + r) >> 1;
        int xx = chack(m);
        if (xx == 1) r = m;
        else l = m;
    }
    printf("%d\n", r);
}

Guess you like

Origin blog.csdn.net/jnxxhzz/article/details/80691533