5.16 CF

C. Robbery
time limit per test
 2 seconds
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 nfrom 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 mtimes 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 nm and k (1 ≤ n ≤ 1041 ≤ 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.



    现在有N个钻石堆,一些贼想偷取钻石,但是安保机制每隔单位时间会检查相邻两个钻石堆的钻石数量之和,得到N - 1个数,然后与上次检查结果的N - 1个数比较,如果发现不同则报警。现在这些贼在单位时间内能够进行M次操作,他们一共有K个单位时间。能够采取的操作包括:①将某堆钻石中的一颗移动到另一堆;②将某钻石堆中的一颗移动到自己的袋子;③将自己袋子中的一颗移动到某钻石堆;现在求这些贼最多能够偷到多少钻石。

    要想保证相邻两堆钻石和不变,那么只能从相邻的两个钻石堆中,从其中一堆移动一颗到另外一堆(假设将 i 堆的一颗钻石移动到 i + 1堆),那么 i 和 i + 1的和保持不变了,但是 i + 1 和 i + 2的和变了,那么我们继续这个过程……当N为偶数时我们无论如何取不到钻石,只有当N为奇数时才能取得,应为当上述操作执行到最后是,N为奇数,那么最后一堆就多了一颗钻石,我们可以将它移动到自己袋子中即可。

    经过这样分析,我们知道,钻石最多不会超过 i (i 为奇数且 1 <= i <= N)堆中的最小值,还要考虑操作的次数。

   一开始的时候没有读出单位时间内最多不超过m次操作的要求。


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll a[100010];

int main()
{
    ll n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    if(n%2==0)
    {
        cout<<0<<endl;
        return 0;
    }
    ll ans=0;
    int need=n/2+1;
    if(need>m) ans=0;
    else
    {
        ans=a[1];
        for(int i=1;i<=n;i++)
            if(i%2)
                ans=min(ans,a[i]);
        ll all=m/need*k;
        ans=min(ans,all);
    }
    cout<<ans<<endl;
    return 0;
}


猜你喜欢

转载自blog.csdn.net/jinghui_7/article/details/80347096
cf
今日推荐