# HackerEarth Will Rick survive or not problem solution

In this HackerEarth Will Rick survive or not problem solution After Governor's attack on the prison, Rick found himself surrounded by walkers. They are coming towards him from all sides. Now, suppose Rick has an infinite number of bullets with him. Suppose Rick needs 1 bullet to kill each walker (yeah he is good at killing walkers. They need to be shot at the head. See, how good he is). Now as soon as he kills 1 walker rest of the walkers move forward by 1 m. There are n walkers each at some distance from Rick. If any walker is able to reach Rick, he dies. Now, you need to tell if he survives or not. If he survives print "Rick now go and save Carl and Judas" else print "Goodbye Rick" followed by no. of walkers he was able to kill before he died in next line. One more thing Rick's gun can fire 6 shots without reloading. It takes him 1 sec to reload and during this time walkers move 1 m forward.

## HackerEarth Will Rick survive or not problem solution.

`#include<bits/stdc++.h>using namespace std;int ar;int main(){    int t;    scanf("%d",&t);    while(t--)    {        memset(ar,0,sizeof(ar));        int n,tmp;        scanf("%d",&n);        for(int i=1;i<=n;++i)        {            scanf("%d",&tmp);            ar[tmp]++;        }        int ans=0,cnt=0,j=0;        bool pos=true;        for(int i=1;i<=n;++i)        {            while(ar[j]==0)                j++;            ar[j]--;            if(j-cnt<=0)            {                pos=false;                break;            }            if(i%6==0 && i!=0)                cnt++;            cnt++;            ans++;        }        if(pos)            printf("Rick now go and save Carl and Judas\n");        else            printf("Goodbye Rick\n%d\n",ans);    }    return 0;}`

### Second solution

`#include<bits/stdc++.h>#define LET(x,a) __typeof(a) x(a)#define TR(v,it) for( LET(it,v.begin()) ; it != v.end() ; it++)#define FORi(i,a,b) for(LET(i,a) ; i<b; i++)#define repi(i,n) FORi(i,(__typeof(n))0,n)#define FOR(i,a,b) for(i=a ; i<b; i++)#define rep(i,n) FOR(i,0,n)#define si(n) scanf("%d",&n)#define DRT()  int t; cin>>t; while(t--)#define DRI(n)  int n; cin>>n; #define DRII(n,m)  int n,m; cin>>n>>m; using namespace std;int A;int main(){    DRT()    {        memset(A,0,sizeof(A));        int x;        DRI(n); repi(i,n){si(x);A[x]++;}        int c=0;        int i;        x=0;        assert(n<=100000);        rep(i,n)        {            while(A[x]==0)x++;            A[x]--;            if(c>= x)break;            c++;             if(i%6==5)c++;        }        if(i==n)            cout<<"Rick now go and save Carl and Judas\n";        else        {            cout<<"Goodbye Rick\n"<<i<<endl;        }    }    return 0;}`