http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5819

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(二分好题+思维)
Plants vs. Zombies(?)
(Image from pixiv. ID: 21790160; Artist: socha)

There are .

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  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 ), indicating the number of plants and the maximum number of steps the robot can take.

The second line contains -th plant.

It's guaranteed that the sum of .

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 have  after the watering.

 

 

用ans输出好像会炸long long ???

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<string>
 6 #include<cstdio>
 7 #include<queue>
 8 #include<vector>
 9 typedef long long ll;
10 #define maxn 100005
11 using namespace std;
12 
13 ll a[maxn];
14 ll book[maxn];
15 ll n,m,ans,Min;
16 bool Check(ll mid){
17     ll tmp;
18     if(mid==0) {
19         Min=0;
20         return true;
21     }
22     Min=0x3f3f3f3f3f3f3f3f;
23     for(int i=1;i<=n+1;i++){
24         book[i]=0;
25     }
26     for(int i=1;i<=n;i++){
27         tmp=mid/a[i];
28         if(a[i]*tmp<mid) tmp++;
29         if(i==n&&book[i]>=tmp) break;
30         book[i]++;
31         if(book[i]<tmp){
32             book[i+1]+=tmp-book[i];
33             book[i]=tmp;
34         }
35         Min=min(Min,a[i]*book[i]);
36     }
37     ll sum=0;
38     for(int i=1;i<=n+1;i++){
39         sum+=book[i];
40         if(sum>m) return false;
41     }
42     return true;
43 }
44 
45 int main(){
46     int T;
47     while(~scanf("%d",&T)){
48         while(T--){
49             scanf("%lld %lld",&n,&m);
50             for(int i=1;i<=n;i++){
51                 scanf("%lld",&a[i]);
52             }
53             ll L,R,mid;
54             L=0,R=(1LL<<60);
55             while(L<=R){
56                 mid=(L+R)/2;
57                 if(Check(mid)){
58                     L=mid+1;
59                   //  ans=Min;
60                 }
61                 else{
62                     R=mid-1;
63                 }
64             }
65             printf("%lld\n",L-1);
66         }
67     }
68 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案