22178_Depo

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

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

Pro.ID

22178

Title

Depot

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    On the circular road surrounding the city, there are N refueling depots. Every depot has a large warehouse (you may assume the storage capacity is infinite), and is connected with two other depots through oil pipes.

    As the circular road is very busy, each depot has to serve such a lot of cars everyday, so the oil is consumed almost the same rapidly at each depot. Usually the depots are respectively supplied by a center warehouse in the city. But recently a war has broken out in Middle East, so the oil supplies are in great shortage, and the center warehouse has no more oil to supply these N depots. But fortunately some of the depots still have a large amount of oil storage. And the oil can be transferred from one depot to another through oil pipes. So, to satisfy the consumption at each depot, the manager of the depots, has decided to rearrange the oil storage, so that each depot contains the same amount of oil.

    The oil transfer can be carried out in unlimited times. But for some strange reasons(security, or ..., who knows), each time the oil transfer should be carried out in a special way, that is a depot must transfer the same amount of oil to its two neighboring depots. What's more, the amount of oil transferred should always be in integer units, and of course can not exceed the current storage of the source depot.

    Since the oil transfer cost is proportional to the amount of oil transferred, and the manager is not sure whether it's possible to make such a transfer plan, so that each depot contains the same amount of oil. So now it's your task to write a program, first answer whether the manager's goal is possible, and if possible, find a transfer plan so that the total amount of oil transferred is minimized.


    输入

    Input may contain several test cases. The first line is a positive integer T ( T ≤ 20 ), denoting the number of test cases followed. Each test case consists of two lines. The first line is a positive integer, N ( 3 ≤ N ≤ 50000 ), indicating the number of depots on the circular road. The second line contains N non-negative integers, a1, a2, ... an, ( ai ≤ 300 ), denoting the number of units of oil in depot 1, depot 2, ..., depot n. For each i satisfying 2 ≤ i < n, depot i is connected with depot i-1 and depot i+1, and depot 1 is also connected with depot n.

    输出

    Description

    On the circular road surrounding the city, there are N refueling depots. Every depot has a large warehouse (you may assume the storage capacity is infinite), and is connected with two other depots through oil pipes.

    As the circular road is very busy, each depot has to serve such a lot of cars everyday, so the oil is consumed almost the same rapidly at each depot. Usually the depots are respectively supplied by a center warehouse in the city. But recently a war has broken out in Middle East, so the oil supplies are in great shortage, and the center warehouse has no more oil to supply these N depots. But fortunately some of the depots still have a large amount of oil storage. And the oil can be transferred from one depot to another through oil pipes. So, to satisfy the consumption at each depot, the manager of the depots, has decided to rearrange the oil storage, so that each depot contains the same amount of oil.

    The oil transfer can be carried out in unlimited times. But for some strange reasons(security, or ..., who knows), each time the oil transfer should be carried out in a special way, that is a depot must transfer the same amount of oil to its two neighboring depots. What's more, the amount of oil transferred should always be in integer units, and of course can not exceed the current storage of the source depot.

    Since the oil transfer cost is proportional to the amount of oil transferred, and the manager is not sure whether it's possible to make such a transfer plan, so that each depot contains the same amount of oil. So now it's your task to write a program, first answer whether the manager's goal is possible, and if possible, find a transfer plan so that the total amount of oil transferred is minimized.


    Input

    Input may contain several test cases. The first line is a positive integer T ( T ≤ 20 ), denoting the number of test cases followed. Each test case consists of two lines. The first line is a positive integer, N ( 3 ≤ N ≤ 50000 ), indicating the number of depots on the circular road. The second line contains N non-negative integers, a1, a2, ... an, ( ai ≤ 300 ), denoting the number of units of oil in depot 1, depot 2, ..., depot n. For each i satisfying 2 ≤ i < n, depot i is connected with depot i-1 and depot i+1, and depot 1 is also connected with depot n.

    Output

    For each test case, if it's impossible to make such a transfer plan, just output "Impossible" (without quotation mark). Otherwise, output an integer in one line, representing the minimum amount of units of oil that should be transferred from one depot to another. No extra blank is allowed.

    Sample Input

    2
    3
    4 1 1
    3
    1 0 1

    Sample Output

    2
    Impossible

    Source

    样例输入

    2
    3
    4 1 1
    3
    1 0 1

    样例输出

    2
    Impossible

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部