Hey guys this is the question's link from hackerrank hackerrank problem
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long int sizeArr, operation;
cin>>sizeArr>>operation;
long int array[sizeArr];
for(long int i=0;i<sizeArr;i++)
array[i]=0;
for(long int i=0;i<operation;i++)
{
long int a,b,k;
cin>>a>>b>>k;
for(long int j=a-1;j<=b-1;j++)
array[j]+=k;
}
sort(array,array+sizeArr);
cout<<array[sizeArr-1];
}
I coded it like this and the another person code it like
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
long int N,M,a,b,k,i,j,max=0,x=0;
cin>>N>>M;
long int *Arr = new long int[N+1]();
for(i=0;i<M;i++)
{
cin>>a>>b>>k;
Arr[a]+=k;
if((b+1)<=N) Arr[b+1]-=k;
}
for(i=1;i<=N;i++)
{
x=x+Arr[i];
if(max<x) max=x;
}
cout<<max;
return 0;
}
Mine one didn't clear all the test cases but the second one's code did. Any suggestions.