2018ICPC青岛区域赛 zoj4062 Plants vs. Zombies

2018ICPC青岛区域赛 zoj4062 Plants vs. Zombies

  BaoBao and DreamGrid are playing the game Plants vs. Zombies. In the game, DreamGrid grows plants to defend his garden against BaoBao's zombies.


Plants vs. Zombies(?)
(Image from pixiv. ID: 21790160; Artist: socha)

There are  plants in DreamGrid's garden arranged in a line. From west to east, the plants are numbered from 1 to  and the -th plant lies  meters to the east of DreamGrid's house. The -th plant has a defense value of  and a growth speed of . Initially,  for all .

DreamGrid uses a robot to water the plants. The robot is in his house initially. In one step of watering, DreamGrid will choose a direction (east or west) and the robot moves exactly 1 meter along the direction. After moving, if the -th plant is at the robot's position, the robot will water the plant and  will be added to . Because the water in the robot is limited, at most  steps can be done.

The defense value of the garden is defined as . DreamGrid needs your help to maximize the garden's defense value and win the game.

Please note that:

  • Each time the robot MUST move before watering a plant;
  • It's OK for the robot to move more than  meters to the east away from the house, or move back into the house, or even move to the west of the house.
Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers  and  (), indicating the number of plants and the maximum number of steps the robot can take.

The second line contains  integers  (), where  indicates the growth speed of the -th plant.

It's guaranteed that the sum of  in all test cases will not exceed .

Output

For each test case output one line containing one integer, indicating the maximum defense value of the garden DreamGrid can get.

Sample Input
2
4 8
3 2 6 6
3 9
10 10 1
Sample Output
6
4
Hint

In the explanation below, 'E' indicates that the robot moves exactly 1 meter to the east from his current position, and 'W' indicates that the robot moves exactly 1 meter to the west from his current position.

For the first test case, a candidate direction sequence is {E, E, W, E, E, W, E, E}, so that we have  after the watering.

For the second test case, a candidate direction sequence is {E, E, E, E, W, E, W, E, W}, so that we haveafter the watering.

 

 

#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 100;
ll n, m;
ll a[maxn];
ll b[maxn];

bool check(ll minn) {
    for (int i = 0; i < n; i++) {
        b[i] = (minn + a[i] - 1ll) / a[i];
    }
    ll sum = 0ll;
    for (int i = 0; i < n; i++) {
        if (b[i] == 0ll) {
            if (i != n - 1ll) sum++;
        } else {
            sum += b[i] * 2ll - 1ll;
            b[i + 1] = b[i + 1] - b[i] + 1ll;
            if (b[i + 1] < 0) b[i + 1] = 0;
        }
        if (sum > m) return 0;
    }
    return sum <= m;
}

int main() {
    //freopen("input.txt", "r", stdin);
    int _;
    cin >> _;
    while (_--) {
        cin >> n >> m;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        ll l = 0, r = 100005 * m;
        ll mid;
        while (l < r) {
            mid = (l + r + 1) / 2;
            if (check(mid)) {
                l = mid;
            } else {
                r = mid - 1;
            }
        }
        cout << l << endl;
    }
    return 0;
}

 

posted @ 2018-11-05 22:15 Albert_liu 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值