Not showing the expected output for a certain input

61 Views Asked by At

I write the code for this problem.

https://codeforces.com/contest/1744/problem/B

My code is perfectly working for the input given below,

Input:

1
1 1
1
1 1

Output:

2

Input:

1
3 3
1 2 4
0 2
1 3
0 5

Output:

11
14
29

Input:

1
6 7
1 3 2 4 10 48
1 6
0 5
0 4
0 5
1 3
0 12
0 1

Output:

80
100
100
100
118
190
196

But for this input:

1
6 7
1000000000 1000000000 1000000000 11 15 17
0 17
1 10000
1 51
0 92
0 53
1 16
0 1

the Output should be like this:

3000000094
3000060094
3000060400
3000060952
3000061270
3000061366
3000061366

But my code is giving some garbage value or wrong output for this code which is:

-1294967202
-1294967202
-1294906896
-1294906344
-1294906026
-1294905930
-1294905930

I couldn't understand where is the main problem. Please help me to fix the problem. Here is my code. If you find the problem please fix it for me. Thanks in advance..

#include<stdio.h>

int odd_even_incre(long long a[], int x, int y,int n)
{
    int i,j;
    long long sum=0;

    if(x%2==0){
        for(i=0; i<n ;i++){
            if(a[i]%2==0){
                a[i]= a[i]+y;
            }
        sum = sum+a[i];
        }
    }
    else{
        for(i=0; i<n ;i++){
            if(a[i]%2!=0){
                a[i]= a[i]+y;
            }
        sum = sum+a[i];
        }
    }
    return sum;
}

int main()
{
    int n,q,t, i,j,x,y;
    long long a[100000],result;

    scanf("%d", &t);

    for(i=0; i<t; i++)
    {
        scanf("%d %d", &n, &q);
        for(j=0 ; j<n ; j++)
        {
            scanf("%lld", &a[j]);
        }
        for (j=0; j<q; j++)
        {
            scanf("%d %d", &x, &y);
            result = odd_even_incre(a,x,y,n);
            printf("%lld\n",  result);
        }
    }

    return 0;
}
1

There are 1 best solutions below

0
Zannatul Ferdousi Hema On

I have been fixed it. It will be just

long long  odd_even_incre(){}

instead of

int odd_even_incre(){}

that's it. Thank you all