Codeforces 567A. Lineland Mail

简介:

Codeforces 567A的传送门

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.

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

题目大意:给你n个有序的整数,让你找出与data[i]相距最大的数和最小的数

直接上代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
int data[maxn];
int main()
{
    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]);
    }
    return 0;
}
目录
相关文章
|
6月前
codeforces 340 A. The Wall
水水的一道题,只需要找xy的最小公倍数,然后找a b区间有多少个可以被xy的最小公倍数整除的数,就是答案。
26 0
|
6月前
uva 11991 - Easy Problem from Rujia Liu?
这个题目的意思是输入n个数,m组询问,每组询问包含两个整数k,v,意思是询问整数v第k次出现的位置。
28 0
|
7月前
|
机器学习/深度学习 Java
【Java每日一题,dfs】[USACO1.5]八皇后 Checker Challenge
【Java每日一题,dfs】[USACO1.5]八皇后 Checker Challenge
|
7月前
BUUCTF Rabbit 1
BUUCTF Rabbit 1
47 0
Contest Print Server组队第四场J
问题 J:Contest Print Server 时间限制: 1 Sec 内存限制: 128 MB 题目描述 In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code any time. Here you need to write a contest print server to handle all the requests.
68 0
|
PHP
CTF入门篇writeup——D0g3 Games
今天在网上找到一个CTF的小游戏,题目我做了几道感觉挺简单,很适合入门,之前了解CTF,参加各种杯或者是看各种比赛题的writeup,感觉太难了,想到这我还是决定从点滴做起,记录一下学习过程,同时也想做一套CTF从入门到精通的教程。
2922 0
|
监控 Linux 开发工具
|
Java 机器学习/深度学习
2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ&#39;s Socks【规律题,数学,水】
KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 338    Accepted Submission(s)...
1031 0