codeforces(567A)--A. Lineland Mail--B. Berland National Library

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
4
-5 -2 2 7
output
3 12
3 9
4 7
5 12
input
2
-1 1
output
2 2
2 2

有n个城市,都在x轴上,从ci到cj之间送信的花费是,ci到cj的距离,现在给出每一个点的坐标xi,问对于第i城市来说花费最大和最小是多少(不能送信给自己,输入是有序的)。

找出n个城市坐标最大和最小的点,对于第i个城市来说,花费最大的是到坐标最大的点或坐标最小的点,花费最小是到第i-1或i+1个点,记录所有的结果,并输出

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std ;
#define LL __int64
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
LL a[100010] , l , r ;
int main() {
    int i , n ;
    scanf("%d", &n) ;
    for(i = 0 ; i < n ; i++)
        scanf("%I64d", &a[i]) ;
    l = a[0] ;
    r = a[n-1] ;
    printf("%I64d %I64d\n", a[1]-a[0] , r - a[0] ) ;
    for(i = 1 ; i < n-1 ; i++) {
        printf("%I64d %I64d\n", min(a[i]-a[i-1],a[i+1]-a[i]) , max(a[i]-l,r-a[i]) ) ;
    }
    printf("%I64d %I64d\n", a[n-1]-a[n-2], a[n-1]-l ) ;
    return 0 ;
}

B. Berland National Library
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.

Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned aregistration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:

  • "+ ri" — the reader with registration number ri entered the room;
  • "- ri" — the reader with registration number ri left the room.

The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.

Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.

Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.

Input

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).

It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

Output

Print a single integer — the minimum possible capacity of the reading room.

Sample test(s)
input
6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7
output
3
input
2
- 1
- 2
output
2
input
2
+ 1
- 1
output
1
Note

In the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 11200and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.



有一个图书馆记录,+ ri代表编号为ri的人进入了图书馆,- ri代表编号为ri的人出去的图书馆,保证数据合法,问图书馆需要最少能容纳多少人。

在记录中有三种情况,先进后出,直接出,只有进,

我们可以记录图书馆当前需要容纳的最少人sum,和我们已知到图书馆现在正有多少人num,那么sum应该大于等于num

一个编号进入,那么num增加1,维护sum

一个编号出去,如果之前有他进去的记录,那么num--,sum不变,如果没有他进去的记录,就证明在记录之前他就进入了,也就是说他一直都在图书馆里,那么sum++。

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std ;
#define LL __int64
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
int a[1000100] ;
int main() {
    int i , n , sum , num , k ;
    char str[10] ;
    memset(a,0,sizeof(a)) ;
    sum = num = 0 ;
    scanf("%d", &n) ;
    while( n-- ) {
        scanf("%s %d", str, &k) ;
        if( str[0] == '+' ) {
            num++ ;
            a[k] = 1 ;
            sum = max(sum,num) ;
        }
        else{
           if( a[k] ) {
                num-- ;
                a[k] = 0 ;
           }
           else {
                sum++ ;
           }
        }
    }
    printf("%d\n", sum) ;
    return 0 ;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值