I was doing \[[this problem:](https://mirror.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.↵
↵
↵
↵
↵
↵
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.↵
↵
↵
↵
↵