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.
process.stdin.resume();process.stdin.setEncoding('ascii');varinput_stdin="";varinput_stdin_array="";varinput_currentline=0;process.stdin.on('data',function(data){input_stdin+=data;});process.stdin.on('end',function(){input_stdin_array=input_stdin.split("\n");main();});functionreadLine(){returninput_stdin_array[input_currentline++];}/////////////// ignore above this line ////////////////////functionmain(){varn_temp=readLine().split(' ');varlistSize=parseInt(n_temp[0]);varlineNumber=parseInt(n_temp[1]);letslopList=newArray();for(leti=0;i<listSize;i++){slopList.push(0);}for(vara0=0;a0<lineNumber;a0++){vara_temp=readLine().split(' ');constbeginElementPos=parseInt(a_temp[0]);constendElementPos=parseInt(a_temp[1]);constaddValue=parseInt(a_temp[2]);slopList[beginElementPos-1]+=addValue;if(endElementPos<listSize){slopList[endElementPos]-=addValue;}}letactualList=newArray();letsum=0;for(leti=0;i<listSize;i++){sum+=slopList[i];actualList.push(sum);}letmax=actualList.reduce((acc,val)=>{return(acc>val)?acc:val;},0);console.log(max);}
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 →