codeforces—— 567A —— Lineland Mail

来源:互联网 发布:淘宝发展前景怎么样 编辑:程序博客网 时间:2024/06/06 03:19
A. Lineland Mail
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.

Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).

Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.

For each city calculate two values ​​mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city

Input

The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence of ndistinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.

Output

Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.

Examples
input
4-5 -2 2 7
output
3 123 94 75 12
input
2-1 1
output
2 22 2
问每个数与其余所有数,差值最小与差值最大
水题
#include<iostream>#include<cmath>#include<cstdio>#include<map>#include<set>#include<cstring>#include<string>#include<algorithm>#define MAX 2e9+8#define min(a,b) ((a)>(b)?(b):(a))using namespace std;int main(){    int n;    while(cin>>n)    {        int temp=n,a[100008],b[100008]={MAX},SUM=0;        while(temp--)            cin>>a[temp];        sort(a,a+n);        for(int i=1; i<n; i++)        {            b[i]=a[i]-a[i-1];            SUM+=b[i];        }        b[n]=MAX;        int sum=0;        for(int i=0;i<n;i++)        {            cout<<min(b[i],b[i+1])<<' '<<max(SUM,sum)<<endl;            sum+=b[i+1];            SUM-=b[i+1];        }    }    return 0;}


原创粉丝点击