### Whitewiz's blog

By Whitewiz, history, 5 weeks ago,

I used accumulate for calculating the sum of elements of the array(which got hacked) however simply calculating the sum via iteration gives the correct result.

Am i missing something or is there any problem with using this "accumulate" thing.

update — this idea of using all the attacks at once (at 1st second) requires to calculate the sum of the array ,but this sum can overflow (long long is insufficient). Better idea is to use the ceil division in the check function like this :

tot += ((have + cool[i] — 1)/cool[i]) * attack[i]; Hacker of the above solution helped me figure this out. Thanks a lot sammyuri sir.

• +3

 » 5 weeks ago, # |   0 Auto comment: topic has been updated by Whitewiz (previous revision, new revision, compare).
 » 5 weeks ago, # | ← Rev. 2 →   +12 It will overflow due to 0 not being a long long, You should use long long sum = accumulate(array.begin(), array.end(), 0ll); instead of long long sum = accumulate(array.begin(), array.end(), 0); 
•  » » 5 weeks ago, # ^ |   0 Oh okay, thanks for the clarification :)
 » 5 weeks ago, # |   +5 You have to use it like this:long long int sum = accumulate(arr.begin(), arr.end(), 0LL);You missed the 0LL.
•  » » 5 weeks ago, # ^ |   0 Thank you very much
 » 5 weeks ago, # | ← Rev. 2 →   0 in the binary search part of this question why the submission using the upper limit as greater than 1e13 got hacked??
•  » » 5 weeks ago, # ^ |   0 because if number of attacks are too large then the accumulated sum (total damage calculated in binary search) in could overflow if expected number of turns is greater than 1e13.
•  » » » 5 weeks ago, # ^ |   0 ohhkk got it!!thanks man
 » 5 weeks ago, # |   0 Auto comment: topic has been updated by Whitewiz (previous revision, new revision, compare).