CodeForces - 567A (Lineland Mail)

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 n distinct 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.

Example
Input
4
-5 -2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2

題意描述:
輸入n個點;
從1-n個點,找出距這個點最大的距離和最小的距離

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

const int maxn=1e5+10;
int x[maxn];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
    scanf("%d",&x[i]);
}
printf("%d %d\n",x[1]-x[0],x[n-1]-x[0]);
for(int i=1;i<n-1;i++){
    printf("%d %d\n",min(x[i]-x[i-1],x[i+1]-x[i]),max(x[n-1]-x[i],x[i]-x[0]));
}
printf("%d %d\n",x[n-1]-x[n-2],x[n-1]-x[0]);
return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章