Skip to content

Instantly share code, notes, and snippets.

@vovuh
Created August 7, 2015 18:34
Show Gist options
  • Save vovuh/ad0ecbd0e81a578d7797 to your computer and use it in GitHub Desktop.
Save vovuh/ad0ecbd0e81a578d7797 to your computer and use it in GitHub Desktop.
#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