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

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-23 06:42:31

Codeforces 567A. Lineland Mail的相关文章

Codeforces 567A 567B 567C 567D

A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi - a coordi

Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序

C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/29/C Description One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B

Codeforces Round #Pi (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/567 听说Round #Pi的意思是Round #314... A. Lineland Mail time limit per test:3 seconds memory limit per test:256 megabytes All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with it

Codeforces Round #Pi (Div. 2) (STL专场)

Codeforces Round #Pi (Div. 2) A - Lineland Mail 水题,拼手速. /* * @author Novicer * language : C++/C */ #include<iostream> #include<sstream> #include<fstream> #include<vector> #include<list> #include<deque> #include<queue

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

A题: 题目地址:Lineland Mail #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include

[codeforces Mail.Ru Cup 2018 Round 1 D][ xor 操作]

http://codeforces.com/contest/1054/problem/D 题目大意:一个序列a1 a2...an,可以对若干个元素进行取反,使所得的新序列异或和为0的区间个数最多. 题目分析:首先易知每个位置的前缀异或和的值只有两种,因为对元素进行取反时,取偶数个元素异或和不变,奇数个元素就是原值取反.然后由于对一个位置取反,不会影响后面位置与这个位置的前缀异或和相同的位置个数(因为这个位置取反后,后面各个位置的前缀异或和也跟着改变),所以一个位置的改变只会影响与前面位置前缀和相

codeforces 710D Two Arithmetic Progressions(线性同余方程)

题目链接: http://codeforces.com/problemset/problem/710/D 分析:给你两个方程 a1k + b1 and a2l + b2,求在一个闭区间[L,R]中有多少个X,X满足 x = a1k' + b1 = a2l' + b2. 由此可以发现这两个方程满足线性同余,即 x ≡b1mod(a1) 且 x≡b2mod(a2); 也就是 a1k' + b1 = a2l' + b2a. 所以 a1k1 + (-a2k2) = (b2 - b1),由同余方程得 :

codeforces 495B Modular Equations 简单数论~

链接:http://codeforces.com/problemset/problem/495/B 首先 a = b(mod x)  可以根据同余定理 b|a-b . 然后从1开始枚举到a-b. 还有一个定理,在sqrt(a-b)范围内 就可以枚举出所有的因子式,例如16,sqrt(16) = 4 , 1 * 16 = 16, 2*8 = 16, 4*4 = 16 再没有其它的式子了(卡在这里了...):: /*******************************************

codeforces 659 G. Fence Divercity 组合数学 dp

http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代码: //File Name: cf659G.cpp //Author: long //Mail: [email protected] //Created Time: 2016年07月12日 星期二 12时40分28秒 #include <stdio.h> #include <string.