Different output on different online ide (Problem: 740B)

Revision en1, by swAira, 2021-05-02 14:26:55

I have tried the code on codechef ide and it gave the desired output but on being submitted here it gave wrong output. I have provided the code and all necessary details below. Please check if you can help with this. Thank you in advance.

Contest:Codeforces Round 381 (Div. 2) Problem:740B - Alyona and flowers Submission:114845312 The code:

#include <stdio.h>
#include <stdlib.h>
int main(){
    int n, q,i,j,s=0,c,b;
    int *a,*ar;
    scanf("%d %d",&n, &q);
    a=(int*)calloc(n,sizeof(int));
    ar=(int*)calloc(q,sizeof(int));
    for (i=0;i<n;i++){
        scanf("%d", &a[i]);
        a[i]+=s;
        s=a[i];
    }
    for (i=0;i<q;i++){
        scanf("%d %d", &c, &b);
        ar[i]=a[b-1]-a[c-2];
        
    }
    j=ar[0];
    for(i=1;i<q;i++){
        j=ar[i-1]+ar[i];
        if(ar[i-1]>ar[i])
            ar[i]=ar[i-1];
        if(j>ar[i])
            ar[i]=j;
    }
    if(ar[q-1]<0)
    ar[q-1]=0;
    s=ar[q-1];
    free(a);
    free(ar);
    printf("%d\n",s);
    return 0;
}

Input: 5 4 1 -2 1 3 -4 1 2 4 5 3 4 1 4

expected output: 7(got it on codechef ide) output on submission (codeforces): 4

Tags doubt, o/p_different, different answer, #wrong_answer

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English swAira 2021-05-02 14:26:55 1242 Initial revision (published)