Codeforces 567A Portal
All cities of Lineland is located on the Ox coordinate axis. Thus, each of the city are associated with their position xi-a coordinate on the Ox axis. No. Cities is located at a single point.
Lineland residents love-to-send letters to all other. A person could send a letter with if the recipient lives in another city (because if they live in the same city and then it is Easier to drop in).
Strange But true, the cost of sending the letter was exactly equal to the distance between the sender's city and the Recipi Ent ' s city.
For each city calculate the 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 T He maximum cost of sending a, the i-th city to some
Input
The first line of the input contains an 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-coordina Te of the i-th city. All the Xi's is distinct and follow in ascending order.
Output
Print n Lines, the i-th line must contain. Integers mini,?maxi, separated by a space, where Mini was the minimum cost of Sending a letter from the I-th city, and Maxi are the maximum cost of sending a letter from the I-th city.
Sample Test (s)
Input
4
-5-2 2 7
Output
3 12
3 9
4 7
5 12
Input
2
-1 1
Output
2 2
2 2
The main topic: give you n ordered integers, let you find out with Data[i] The largest number and the smallest number
Directly on the code:
#include <iostream>#include <cstdio>#include <algorithm>usingnamespace Std;Constint maxn=1e5+5;int Data[MAXN];intMain () {int m; while (~SCANF ("%d", &m)) {for (int i=0; i<m; i++) scanf ("%d",& Data[i]);printf"%d%d\n", Data[1]-data[0], data[m-1]-data[0]];for (int i=1; i<m-1; i++) {printf ("%d%d\n", Min ( Data[i]-data[i-1], data[i+1]-data[i]], Max ( Data[m-1]-data[i],data[i]-data[0]];} printf ("%d%d\n", Data[m-1]-data[m-2],data[m-1]-data[0]];} return0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 567A. Lineland Mail