Strange observation with accumulate() function in STL
Difference between en1 and en2, changed 45 character(s)
I was doing \[[this problem:](https://codeforces.com/contest/1512D] /problem/D) and i noticed a strange thing.↵

In order to calculate sum of the vector elements , I used the accumulate function available in STL↵






~~~~~↵
typedef long long ll;↵
#define int ll↵
//the sum variable and elements in vector becomes long long type↵
int sum=0;↵
sum=accumulate(v.begin(),v.end(),0);↵
~~~~~↵
 [submission:127183042]↵

This basically gives the wrong answer . ↵


But↵



~~~~~↵
#define int ll↵
int sum=0;↵
sum=accumulate(v.begin(),v.end(),sum);↵
or↵
sum=accumulate(v.begin(),v.end(),0LL);↵

~~~~~↵
[submission:127184393] ↵

[submission:127184828]↵


gets accepted.↵



#### _**Why is this happening ?**_↵


All these days, I thought it is just an initial value that we give to the accumulate function (the last argument), but it is not just an initial value and plays a big role in the outcome of the sum.↵



I am telling it isn't just a value because ↵

~~~~~↵
ll sum=10;↵
sum+=20;↵
~~~~~↵


Now it wouldn't matter if 20 is given in LL or not , but here 0 gives WA but 0LL is accepted.↵




History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Letscode_sundar 2021-08-27 13:48:31 45 Tiny change: 'problem/D)and i noti' -> 'problem/D) and i noti'
en1 English Letscode_sundar 2021-08-27 13:47:12 1130 Initial revision (published)