POJ 3465 Battle 题解：可“反悔”的贪心

|

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 $H_1$ hit points (HP) at the beginning of the battle, and Heilong has $H_2$. Heilong attacks you each time you do an action, and deal $A_i$ 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, $N, x, y, H_1, H_2. 1 \leqslant N \leqslant 10^5, 1 \leqslant x,y \leqslant 10^4, 1 \leqslant H_1,H_2 \leqslant 10^9$. Then follow $N$ lines, the $i$-th line contains one integer $A_{i-1}$. $1 \leqslant A_{i-1} \leqslant 10^4$.

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.

Translation

• 攻击：让黑龙血量减去 $x$；
• 防御：抵御这一轮黑龙的攻击；
• 回血：回复 $y$ 点生命值。

Code

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

using namespace std;
const int maxn=100005;
int n,x,y,h1,h2,ans=0,a[maxn];
struct Element{
int x,id;
bool operator <(Element b)const{
return x<b.x;
}
};
priority_queue <Element> heap;

int ret=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
return ret*f;
}

int main(){
int now1=h1,now2=h2,lst=0;
for (int i=1;i<=n;i++){
now2-=x;
if (now2<=0){
printf("Win\n%d\n",i);
return 0;
}
now1-=a[i];heap.push((Element){a[i],i});
if (now1<=0){
ans=h2-now2;lst=i;
break;
}
}
if (now1>0) {printf("Lose\n%d\n",ans);return 0;}
while (!heap.empty()){
Element now=heap.top();heap.pop();
now1+=max(y,now.x);
now2+=x;
for (int i=lst+1;i<=n;i++){
now2-=x;
if (now2<=0){
printf("Win\n%d\n",i);
return 0;
}
now1-=a[i];heap.push((Element){a[i],i});
if (now1<=0){
ans=max(ans,h2-now2);lst=i;
break;
}
if (i==n) ans=max(ans,h2-now2),lst=n;
}
if (lst>=n) break;
}
printf("Lose\n%d\n",ans);
return 0;
}