We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Can anyone help me if I use brute force method i get time complexity errors, but i modifiy the above code to c Test case 0 doesnt pass...
#include<stdio.h>
#include<stdlib.h>
long int arrAddition(long a,long b, long k, long *arr)
{
long int max=-1000;
for(long int i=a-1;i<b;i++)
{
arr[i]= arr[i]+k;
if(max<arr[i])
{
max=arr[i];
}
}
return max;
}
int main()
{
long long int n,m,x=0;
long long int a,b,k;
scanf("%lld %lld",&n,&m);
long int *arr=(long*)malloc(n* sizeof(long));
long int *arr1=(long*)malloc(m* sizeof(long));
long int max1=0;
for(long long int i=0;i<m;i++)
{
scanf("%lld", &a);
scanf("%lld", &b);
scanf("%lld", &k);
//arr1[i]=arrAddition(a,b,k,arr);
arr[a]+=k;
if((b+1)<=n)
{
arr[b+1]-=k;
}
}
for(long long int i=1;i<=n;i++)
{
x=x+arr[i];
if(max1<x)
{
max1=x;
}
}
/*
for(long long int i=0;i<m;i++)
{
if(max1<arr1[i])
{
max1=arr1[i];
}
}
*/
printf("%ld",max1);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
Can anyone help me if I use brute force method i get time complexity errors, but i modifiy the above code to c Test case 0 doesnt pass...
}