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.
#include<bits/stdc++.h>usingnamespacestd;vector<string>split_string(string);// Complete the arrayManipulation function below.longarrayManipulation(intn,vector<vector<int>>queries){vector<longlongint>values(n);longlongintmaximum;for(intl=0;l<values.size();l++){values[l]=0;}inti=0,j=0;for(i=0;i<queries.size();i++){for(j=1;j<=n;j++){if(j==queries[i][0]||j==queries[i][1])values[j-1]=values[j-1]+queries[i][2];}}maximum=values[0];for(intp=1;p<values.size();p++){if(values[p]>maximum)maximum=values[p];}returnmaximum;}intmain(){ofstreamfout(getenv("OUTPUT_PATH"));stringnm_temp;getline(cin,nm_temp);vector<string>nm=split_string(nm_temp);intn=stoi(nm[0]);intm=stoi(nm[1]);vector<vector<int>>queries(m);for(inti=0;i<m;i++){queries[i].resize(3);for(intj=0;j<3;j++){cin>>queries[i][j];}cin.ignore(numeric_limits<streamsize>::max(),'\n');}longresult=arrayManipulation(n,queries);fout<<result<<"\n";fout.close();return0;}vector<string>split_string(stringinput_string){string::iteratornew_end=unique(input_string.begin(),input_string.end(),[](constchar&x,constchar&y){returnx==yandx==' ';});input_string.erase(new_end,input_string.end());while(input_string[input_string.length()-1]==' '){input_string.pop_back();}vector<string>splits;chardelimiter=' ';size_ti=0;size_tpos=input_string.find(delimiter);while(pos!=string::npos){splits.push_back(input_string.substr(i,pos-i));i=pos+1;pos=input_string.find(delimiter,i);}splits.push_back(input_string.substr(i,min(pos,input_string.length())-i+1));returnsplits;}
What is wrong with my code it even not passing sample testcase 2
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 →
What is wrong with my code it even not passing sample testcase 2