sort(arr.begin(), arr.end());
int ans= 0;
int i=0; int j=0; int sum=0;
while(j<n){
while( arr[j].first-arr[i].first>=k){
sum-=arr[i].second; i++;
}
while(j<n && (arr[j].first-arr[i].first)<k){
sum+=arr[j].second; j++;
// cout<<sum<<" ";
}cout<<endl;
ans= max(ans, sum);
// cout<<sum<<" "<<ans<<endl;
}
cout<<ans<<endl;
And?
he is being educational and showing us a good implementation of two pointers!
I don't care about this. Dunno what to do with this.
skeptic interpretation: he's showing off and trying to get attention and contribution. meh.