c++ - Can someone please tell me what is wrong with this logic? -


i solving question on hackerrank. following question (in brief):

there exist n robbers trying rob bank. can stay there atmost g minutes. 2 robbers can enter vault @ time.

a[]={a_1,a_2,...,a_n} is user specified array such that a_i is time the i_th robber wishes stay in vault.

a heist successful if robbers wish.

given n,g, a[]; the output must "success" or "failure".

my logic follows: sort(a) in descending order define slot1 , slot2 1st , 2nd person in vault respectively slot1=slot2=g fill in slot1 , slot2 sorted a, such whenever robber finished in slot, next 1 takes place if robbers can accommodated, success, else failure.

i try having double pass. first, add time robbers want, halve , round up. that's ideal time. (at point, check if 1 of robbers at/over amount; if so, that's limit.) then, try fit robbers time frame. if can fit them evenly, you're good. otherwise, increase time , try again.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -