Created
August 7, 2015 18:34
-
-
Save vovuh/ad0ecbd0e81a578d7797 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include <map> | |
#include <set> | |
#include <queue> | |
#include <stack> | |
#include <bitset> | |
#include <time.h> | |
#include <string> | |
#include <vector> | |
#include <math.h> | |
#include <cstdio> | |
#include <cassert> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
#define ft first | |
#define sc second | |
#define mp make_pair | |
#define all(a) a.begin(), a.end() | |
#define forn(i, n) for (int i = 0; i < int(n); i++) | |
typedef long long li; | |
typedef long double ld; | |
typedef pair <li, li> pli; | |
typedef pair <int, int> pii; | |
const int N = 200000, INF = int(2e9); | |
pii x[N]; | |
int n, minans[N], maxans[N]; | |
int main() | |
{ | |
scanf("%d", &n); | |
forn(i, n) | |
{ | |
scanf("%d", &x[i].ft); | |
x[i].sc = i; | |
} | |
sort(x, x + n); | |
forn(i, n) | |
{ | |
if(i == 0) | |
minans[x[i].sc] = abs(x[i + 1].ft - x[i].ft); | |
else if(i == n - 1) | |
minans[x[i].sc] = abs(x[i - 1].ft - x[i].ft); | |
else | |
minans[x[i].sc] = min(abs(x[i + 1].ft - x[i].ft), abs(x[i - 1].ft - x[i].ft)); | |
if(i == 0) | |
maxans[x[i].sc] = abs(x[n - 1].ft - x[i].ft); | |
else if(i == n - 1) | |
maxans[x[i].sc] = abs(x[0].ft - x[i].ft); | |
else | |
maxans[x[i].sc] = max(abs(x[0].ft - x[i].ft), abs(x[n - 1].ft - x[i].ft)); | |
} | |
forn(i, n) | |
printf("%d %d\n", minans[i], maxans[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment