poj 3465 回溯+贪心

Battle
Time Limit: 2000MS Memory Limit: 131072K
Total Submissions: 1911 Accepted: 476

Description

You're Zhu Rengong, a formidable hero. After a number of challenging missions, you are finally facing the final Boss – a black dragon called Heilong. Due to his overwhelming power, you have to plan your actions carefully.

You have H1 hit points (HP) at the beginning of the battle, and Heilong has H2. Heilong attacks you each time you do an action, and deal Ai points of damage in the i-th round. You have three kinds of actions.

  • Attack. You attack Heilong, and do x points of damage.
  • Defend. You focus on avoiding the attack of Heilong. This action nullifies Heilong's attack in this round.
  • Heal. You heal yourself, adding y hit points to yourself. There is no upper bound on your HP.

If anyone's HP drop below or equal to 0, he dies. If you can't kill the dragon within N rounds, you will also die. So you need to know how many rounds you need to kill the black dragon. If you cannot kill him, you will have to calculate the maximal damage you can do on Heilong.

Input

The first line contains five integers, NxyH1H2. 1 ≤ N ≤ 105, 1 ≤ x,y ≤ 104, 1 ≤ H1,H2 ≤ 109. Then follow N lines, the ith line contains one integer Ai-1. 1 ≤ Ai-1 ≤ 104.

Output

If you can kill Heilong, the first line of your output should be "Win". Otherwise "Lose".
The second line contains the number of rounds you need to kill Heilong if the first line is "Win", or the maximal damage you can do if the first line is "Lose".

Sample Input

Sample Input 1 4 1 1 3 3 1 10 1 10

Sample Input 2 4 1 1000 1 4 1 10 1 1

Sample Output

Sample Output 1 Win 4

Sample Output 2 Lose 3

Hint

In Sample 1, you have to defend in the 2nd round, othewise you will die. 
In Sample 2, you heal yourself in the first round, and keep attacking until  N rounds expires.

Source

POJ Monthly--2007.11.25, Yang Yi


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

#define maxn 100001
int n,x,y,h1,h2;
int a[maxn];

int main()
{
    while(~scanf("%d%d%d%d%d", &n, &x, &y, &h1, &h2)){
        for(int i = 0; i < n; i++)
            scanf("%d", a+i);

        priority_queue<int> que;
        int tmp = h2;
        int ans = 0, maxi = 0;
        for(int i = 0; i < n; i++){
            if(h2 <= x){
                ans = i+1;
                break;
            }

            que.push(max(y, a[i]));
            h2-=x;
            maxi = max(tmp-h2, maxi);
            h1-=a[i];
            while(h1 <= 0 && !que.empty()){
                h1 += que.top(); que.pop();
                h2 += x;
            }
        }

        if(ans)
            printf("Win\n%d\n", ans);
        else printf("Lose\n%d\n", maxi);


    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值