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.
Your solution is simply amazing!!! I spent an whole hour scratching my head thinking about disjoint sets!!
Here I what wrote it in C++ using map better allocation.
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
Your solution is simply amazing!!! I spent an whole hour scratching my head thinking about disjoint sets!! Here I what wrote it in C++ using map better allocation.
define ll long long int
using namespace std;
int main() { ll n,m,a,b,k; cin>>n>>m; map arr; while(m--){ cin>>a>>b>>k; if(arr.find(a)==arr.end()) arr[a]=0; arr[a]+=k; if(arr.find(b)==arr.end()) arr[b]=0; arr[b+1]-=k; } ll max=0,x=0; map::iterator i; for(i=arr.begin();i!=arr.end();i++){ x+=i->second; if(x>max){ max=x; } } cout<
Thanks man!! I was thinking to quit but your answer gave me spirit to keep continuing.