题目来源:
http://poj.org/problem?id=3465
排位赛遇到的一道,直接贪心。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
ll a[100100];
int main()
{
ll T,n,i,j,h1,h2,x,y;
scanf("%lld%lld%lld%lld%lld",&n,&x,&y,&h1,&h2);
for(i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
ll cnt=0,ans=0,MAX=-1;
priority_queue<int>qq;//优先队列,数值大的先出列。
for(i=1;i<=n;i++)
{
cnt++;//表示次数
if(h2<=cnt*x)
{
break;
}
MAX=max(MAX,cnt);
h1-=a[i];
qq.push(max(a[i],y));
while(h1<=0&&!qq.empty())
{
h1+=qq.top();
qq.pop();
cnt--;
}
}
if(i<=n)
{
printf("Win\n");
printf("%lld",i);
}
else
{
printf("Lose\n");
ans=MAX*x;
printf("%lld",ans);
}
return 0;
}