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 ;
}
 

Codeforce 567A - Lineland Mail的更多相关文章

  1. Codeforces Round #Pi (Div. 2) A. Lineland Mail 水

    A. Lineland MailTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/proble ...

  2. Codeforces Round #Pi (Div. 2) A. Lineland Mail 水题

    A. Lineland MailTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/probl ...

  3. codeforces Round #Pi (div.2) 567ABCD

    567A Lineland Mail题意:一些城市在一个x轴上,他们之间非常喜欢写信交流.送信的费用就是两个城市之间的距离,问每个城市写一封信给其它城市所花费的最小费用和最大的费用. 没什么好说的.直 ...

  4. CodeForces 567A Gerald is into Art

    http://codeforces.com/problemset/problem/567/A A. Lineland Mail time limit per test 3 seconds memory ...

  5. Codeforces Round #Pi (Div. 2) ABCDEF已更新

    A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  6. Codeforces Round #Pi (Div. 2)(A,B,C,D)

    A题: 题目地址:Lineland Mail #include <stdio.h> #include <math.h> #include <string.h> #i ...

  7. ABP源码分析七:Setting 以及 Mail

    本文主要说明Setting的实现以及Mail这个功能模块如何使用Setting. 首先区分一下ABP中的Setting和Configuration. Setting一般用于需要通过外部配置文件(或数据 ...

  8. Linux发邮件之mail命令

    一.mail命令 1.配置 vim /etc/mail.rc 文件尾增加以下内容 set from=1968089885@qq.com smtp="smtp.qq.com" set ...

  9. php mail 函数发送邮件

    当然你可以通过php ,在自己的站点制作一个反馈表单, 我这次的需求是用email 的形式发送数据报表,结构比较简单 // 收件人地址(此处只可以写一个地址,写多个地址,只有最后一个地址生效) $to ...

随机推荐

  1. 【C#】写文件时如何去掉编码前缀

    我们都知道,文件有不同的编码,例如我们常用的中文编码有:UTF8.GK2312 等. Windows 操作系统中,新建的文件会在起始部分加入几个字符的前缀,来识别编码. 例如,新建文本文件,写入单词 ...

  2. flex布局小结

    2009年,W3C 提出了一种新的方案----Flex 布局,可以简便.完整.响应式地实现各种页面布局.目前,它已经得到了所有浏览器的支持. Flex 是 Flexible Box 的缩写,意为&qu ...

  3. [20200211]使用DBMS_SHARED_POOL.MARKHOT与sql_id的计算.txt

    [20200211]使用DBMS_SHARED_POOL.MARKHOT与sql_id的计算.txt --//以前写的,使用DBMS_SHARED_POOL.MARKHOT标记热的sql_id,这样相 ...

  4. input禁止输入的方法

    1: readonly规定输入字段为只读可复制,但是,用户可以使用Tab键切换到该字段,可选择,可以接收焦点,还可以选中或拷贝其文本. <input type="text" ...

  5. modbus 协议说明及常用格式

    --- 说明: modbus协议一般适用于一个主设备访问多个从设备的硬件开发环境,类似于zigbee网络中的一个路由器多个协调器的一对多模型. modbus常用的寄存器类型为 3X 保持寄存器和 4X ...

  6. Android开发中按钮的语法

    按钮的主要作用就是触发一个动作,所以会用到监听器. 如何为按钮添加单机事件监听器: 1.匿名内部类作为单机事件监听器 案例: 首先在.xml文件中添加一个按钮一,然后设置其id属性,然后在main里获 ...

  7. Go 与 PHP 的语法对比

    Go 是由 Google 设计的一门静态类型的编译型语言.它有点类似于 C,但是它包含了更多的优点,比如垃圾回收.内存安全.结构类型和并发性.它的并发机制使多核和网络机器能够发挥最大的作用.这是 Go ...

  8. Dart中类的getter和setter

    Dart类Getters和Setter Getters和Setter(也称为访问器和更改器)允许程序分别初始化和检索类字段的值. 使用get关键字定义getter或访问器.Setter或存取器是使用s ...

  9. SQL Server无法连接到服务器 标题: 连接到服务器 ------------------------------ 无法连接到 DESKTOP-J6I1UIC\SQLEXPRESS1。 ------------------------------ 其他信息: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。

    解决方案: 打开 SQL server 配置管理器 选择 SQL server 服务,找到服务器,右键启动

  10. element使用

    官方网址: 点击 全局使用 1.创建项目 vue init webpack vue-ele 配置 2.安装依赖 npm install 3.安装loader模块(开发) npm install sty ...