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;