Codeforces A. Lineland Mail
2015-08-06 18:10
483 查看
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 coordinate on the Oxaxis. 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 ofn 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 inascending 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
output
input
output
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 coordinate on the Oxaxis. 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 ofn 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 inascending 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
#include<stdio.h> #include<algorithm> using namespace std; #define ll __int64 const int N = 100005; struct node{ ll id,x,maxdis,mindis; }ans ; bool cmp1(node aa,node bb) { return aa.x<bb.x; } bool cmp2(node aa,node bb) { return aa.id<bb.id; } int main() { int n; while(scanf("%d",&n)>0){ for(int i=0; i<n; i++) { scanf("%I64d",&ans[i].x); ans[i].id=i; } if(n==1) { printf("0 0\n");continue; } sort(ans,ans+n,cmp1); ans[0].maxdis=ans[n-1].x-ans[0].x; ans[0].mindis=ans[1].x-ans[0].x; for(int i=1; i<n; i++) { ll m=ans[n-1].x-ans[i].x , tm; tm=ans[i].x-ans[0].x; ans[i].maxdis=m>tm?m:tm; m=ans[i].x-ans[i-1].x; if(i!=n-1) tm=ans[i+1].x-ans[i].x; else tm=m; ans[i].mindis=m<tm?m:tm; } sort(ans,ans+n,cmp2); for(int i=0; i<n; i++) printf("%I64d %I64d\n",ans[i].mindis,ans[i].maxdis); } }
相关文章推荐
- 2015 Multi-University Training Contest 6
- 实参和形参指针做函数参数时,如何改变main函数变量的值
- Keychain的简单使用
- 屏蔽控制台应用程序的窗口#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
- 接收对 http://192.168.1.18:8001/ObtainData/Service 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。
- HDU 5363 Key Set(2015 Multi-University Training Contest 6 2015多校联合)
- Contains Duplicate III
- 杭电1702ACboy needs your help again!
- RAID 5
- Dell-硬件Raid详细图解步骤
- NSSearchPathForDirectoriesInDomains
- constraint的用法
- Xcode6 svn check out项目出现“The operation couldn’t be completed. (NSURLErrorDomain error -1012.)”的解决方案
- 2015 Multi-University Training Contest 5(HDOJ5351)
- no project are available for deployment to this server&n
- svn cleanup failed–previous operation has not finished 解决方法
- (暴力枚举) UVa 10976 Fractions Again?!
- UVa 10986 Sending email (最短路+Dijkstra队列优化)
- poj3216Repairing Company 二分匹配之最小路径覆盖+floyd
- opencontrail本地编译定义标签