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, andmaxi 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.

Examples
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个城市坐标最大和最小的点,对于第i个城市来说,花费最大的是到坐标最大的点或坐标最小的点,花费最小是到第i-1或i+1个点,记录所有的结果,并输出

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long LL;
const int N=;
const int mod=1e9+;
LL a[] , l , r ;
int main() {
int i , n ;
scanf("%d", &n) ;
for(i = ; i < n ; i++)
scanf("%I64d", &a[i]) ;
l = a[] ;
r = a[n-] ;
printf("%I64d %I64d\n", a[]-a[] , r - a[] ) ;
for(i = ; i < n- ; i++) {
printf("%I64d %I64d\n", min(a[i]-a[i-],a[i+]-a[i]) , max(a[i]-l,r-a[i]) ) ;
}
printf("%I64d %I64d\n", a[n-]-a[n-], a[n-]-l ) ;
return ;
}
 

最新文章

  1. JS中 call() 与apply 方法
  2. [Java 进阶]异常
  3. 浅谈压缩感知(三十):压缩感知重构算法之L1最小二乘
  4. iTween_ValueTo函数
  5. UITableView的分割线不满屏的解决方法
  6. WINDOWS操作系统中可以允许最大的线程数(线程栈预留1M空间)(56篇Windows博客值得一看)
  7. Unity--关于优化方面的那些事儿(一)
  8. FineUIMvc随笔 - 不能忘却的回发(__doPostBack)
  9. react实现双向绑定
  10. plsql本机不安装数据库连接远程数据库
  11. 【Java学习笔记之二】java标识符命名规范
  12. iOS-image图片压缩
  13. Springboot项目配置druid数据库连接池,并监控统计功能
  14. 软件测试-homework3
  15. (原)DropBlock A regularization method for convolutional networks
  16. D - C Looooops POJ - 2115 欧几里德拓展
  17. Java 求两个数百分比%
  18. BZOJ5018:[SNOI2017]英雄联盟(背包DP)
  19. leetcode485
  20. Python之reduce函数

热门文章

  1. LINQ标准查询运算符的执行方式-即时
  2. 零基础学到什么程度可以找一份web前端工作?
  3. Ream--(objc)写事务精简方案
  4. VMware使用与安装
  5. vue使用JSEncrypt实现rsa加密及挂载方法
  6. imx6ull+debian10 构建静态qt交叉编译环境
  7. 退役记——CCC2020&amp;CCO2020
  8. ConcurrentHashMap的size()方法(1.7和1.8)
  9. springboot打成jar包并携带第三方jar
  10. tensorflow 中的L1和L2正则化