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.
Accepted — (https://codeforces.me/contest/1985/submission/265437274) ,(https://codeforces.me/contest/1985/submission/265439252)
Hacked — (https://codeforces.me/contest/1985/submission/265303752)
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.
Auto comment: topic has been updated by Whitewiz (previous revision, new revision, compare).
It will overflow due to 0 not being a long long, You should use
instead of
Oh okay, thanks for the clarification :)
You have to use it like this:
long long int sum = accumulate(arr.begin(), arr.end(), 0LL);
You missed the 0LL.
Thank you very much
in the binary search part of this question why the submission using the upper limit as greater than 1e13 got hacked??
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.
ohhkk got it!!thanks man
Auto comment: topic has been updated by Whitewiz (previous revision, new revision, compare).