【ZCMU2203】Robbery(思维)

题目链接

2203: Robbery

Time Limit: 2 Sec  Memory Limit: 256 MB
Submit: 19  Solved: 7
[Submit][Status][Web Board]

Description

A. Robbery

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.

Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.

Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an n-1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.

Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.

In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe's pocket, is considered his loot.

Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning.

Input

The first line contains integers n, m and k (1≤n≤104, 1≤m,k≤109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell − it is an integer from 0 to 105.

Output

Print a single number − the maximum number of diamonds Joe can steal.

Examples

Input

2 3 1
2 3

Output

0

Input

3 2 2
4 1 3

Output

2

Note

In the second sample Joe can act like this:

The diamonds' initial positions are 4 1 3.

During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.

By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.

During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.

By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.

Now Joe leaves with 2 diamonds in his pocket.

【题意】

有n个房间,房间里有a[i]个宝石,有以下3种操作:从一个房间拿出1个宝石放到另一个房间,从1个房间拿出1个宝石放入口袋,从口袋里拿出1个宝石放入房间,有k分钟,每分钟可以进行m个操作,要求每两个相邻房间的宝石总数不变,计算最多能拿多少个宝石。

【解题思路】

通过简单模拟发现n为偶数是不可以的,当n为奇数时,假如是4 3 1 2 5,为了保证两个相邻房间的宝石总数不变,需要从奇数位置拿一个宝石到偶数位,最后再拿走最后1个位置上的1个宝石,也就是说每拿1个宝石需要进行(n-1)/2+1步操作,如果这个操作>m时,说明这1分钟它一个宝石都拿不了,如果比它小,则计算k*m/(n-1)/2+1。当然不能忘记最后需要与奇数位上最少的宝石数相比,取最小的。

【代码】

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e4+5;
const int INF=0x3f3f3f3f;
LL a[maxn];
int main()
{
    LL n,m,k,ans=INF;
    scanf("%lld%lld%lld",&n,&m,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        if(i%2==0)ans=min(ans,a[i]);
    }
    if(n%2==0)printf("0\n");
    else
    {
        LL t=(n-1)/2+1;
        if(t>m)printf("0\n");
        else
        {
            t=m/t*k;
            ans=min(ans,t);
            printf("%lld\n",ans);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39826163/article/details/83413637