JRY is Fighting
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 104 Accepted Submission(s): 34
The hero has a magic bottle which can store HPs. At first, the bottle is empty. Each time after the hero got hurt, the bottle can get k more HPs, and the hero can decide whether he will release the HPs in the bottle. If he does, he will gain the HPs in the bottle and the bottle will be empty.
We define the hero's operating sequence as s, representing that he used the magic bottle at the si-th seconds. |s| represent the times he used, as well as the length of the sequence.
Now, you should maximize the mininum time interval between two adjacent operation. In other words, let T=max{min{si−si−1}(1<i≤|s|)}, you should find the value of T. We can easily find that if |s|≤1, T=+∞.
You should give him a plan as an operating sequence s which is right for the hero to survive successfully. The hero is so strict that you should find the lexicographically smallest one.
Sequence u1,u2,⋯,un is lexicographically smaller than sequence v1,v2,⋯,vm, if
n<m and u1=v1,u2=v2,⋯,un=vn, or
there exists an integer k(1≤k≤min(n,m)) where u1=v1,u2=v2,⋯,uk−1=vk−1 and uk<vk all hold.
The first line contains three space-separated integers each, n(1≤n≤500000), m(1≤m≤106), k(1≤k≤100).
The second line contains n space-separated integers, ai(0≤|ai|≤100).
If T=+∞, print "Poor JRY!".
Otherwise, print three lines:
The first line, an integer, representing the value of T.
The second line, an integer, |s|.
The third line, |s| space-separated intergers, si.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
#define sf scanf
#define mx 100000000
struct node{
int id,v;
//friend bool operator<(node a,node b){return (a.v==b.v)?(a.id>b.id):(a.v>b.v);}
bool operator < (const node &a)const {
if(a.v==v)return id>a.id;
return v<a.v;
}
};
priority_queue<node> que1,que2;
queue<int> que;
int n,m,k;
int g[1000000],sum[1000000],a[1000000],r[1000000];
int main()
{
#ifdef ACBang
freopen("j.in","r",stdin);
freopen("1010.out","w",stdout);
#endif // ACBang
while(~scanf("%d%d%d",&n,&m,&k))
{
while(!que1.empty()) que1.pop();
while(!que2.empty())que2.pop();
for(int i = 1;i<=n;i++) {sf("%d",a+i);sum[i]=sum[i-1]+a[i];}
int t = 0;
for(int i = 0;i<=n;i++){while(t<=n&&sum[t]<i*k + m) t++;r[i] = t-1;}
for(int i = n;i>0;i--)
{
g[i] = 0;
if(r[i] == n) g[i] = mx + i;
else
{
while(!que1.empty()){
node tmp = que1.top();
if(tmp.id>r[i])que1.pop();
else if(tmp.v*2>=g[tmp.id] + i)
{
que2.push(node{tmp.id,g[tmp.id]-tmp.id});
que1.pop();
}
else break;
}
while(!que2.empty())
{
node tmp = que2.top();
if(tmp.id>r[i])que2.pop();
else break;
}
if(!que1.empty())g[i] = max(g[i],que1.top().v);
if(!que2.empty())g[i] = max(g[i],que2.top().v+i);
}
if(g[i]>i) que1.push((node){i,i});
else que2.push((node){i,g[i]-i});
}
for(int i = 1;i<=n;i++)g[i]-=i;
g[0] = 0;
for(int i = 1;i<=r[0];i++) g[0] = max(g[0],g[i]);
if(g[0] > n) puts("Poor JRY!");
else if(!g[0]) puts("Poor Hero!");
else
{
printf("%d\n",g[0]);
int i = 1;
while(g[i]!=g[0]) i++;
//cout<<T<<":"<<g[1]<<endl;
que.push(i);
while(g[i]!=mx)
{
//cout<<i<<":"<<g[i]<<"---"<<endl;
int j=i+g[0];
while(g[j]<g[0]) {
// cout<<j<<"---"<<g[j]<<" "<<j-i<<endl;
// getchar();
j++;
}
i = j;
que.push(i);
// cout<<i<<endl;
}
printf("%d\n",que.size());
while(!que.empty())
{
int tmp = que.front();
printf("%d",tmp);
que.pop();
if(que.size())printf(" ");
else printf("\n");
}
}
}
return 0;
}