21852_SAFE

2022-5-16 18:20| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505902062900-Problem List-采集的数据-后羿采集器.html

Pro.ID

21852

Title

SAFE

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21852

AC

1

Submit

1

Ratio

100.00%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
  • 描述

    Mirko has decided to rob mini-safe owned by his son so that he could take away some football stickers which are missing in his big sticker collection.

    Lock on the safe consists of N equal discs, each of them being divided in 10,000,000 equal segments numbered from 1 to 10,000,000 clockwise. In the begining, segments on discs having the same number are placed one above (beneath) the other. Discs are layed one on the other such that the segments are overlaping and each disc is missing exactly one segment that is called hole.

    In order to unlock the lock, all holes must be one above (beneath) the other.In one second, Mirko can turn one disc in one direction (clockwise or counterclockwise) for one segment.

    Write a program which will find the minimal time that Mirko needs to open the safe.

    输入

    The first line of the input contains an integer N, 2 ≤ N ≤ 100,000, the number of discs.

    The next N lines contain data describing the initial positions of the holes on each disc.

    The (i+1)-th line contains an integer Pi, 1 ≤ Pi ≤ 10000000, the initial position of the hole on the i-th disc.

    输出

    Description

    Mirko has decided to rob mini-safe owned by his son so that he could take away some football stickers which are missing in his big sticker collection.

    Lock on the safe consists of N equal discs, each of them being divided in 10,000,000 equal segments numbered from 1 to 10,000,000 clockwise. In the begining, segments on discs having the same number are placed one above (beneath) the other. Discs are layed one on the other such that the segments are overlaping and each disc is missing exactly one segment that is called hole.

    In order to unlock the lock, all holes must be one above (beneath) the other.In one second, Mirko can turn one disc in one direction (clockwise or counterclockwise) for one segment.

    Write a program which will find the minimal time that Mirko needs to open the safe.

    Input

    The first line of the input contains an integer N, 2 ≤ N ≤ 100,000, the number of discs.

    The next N lines contain data describing the initial positions of the holes on each disc.

    The (i+1)-th line contains an integer Pi, 1 ≤ Pi ≤ 10000000, the initial position of the hole on the i-th disc.

    Output

    The first and only line of the output should contain the minimal time (in seconds).

    Note: take care of the size of that number.

    Sample Input

    4
    9999999
    7
    16
    9999995

    Sample Output

    29

    Source

    样例输入

    4
    9999999
    7
    16
    9999995

    样例输出

    29

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部