2811guin's blog

By 2811guin, history, 23 months ago, In English
    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;

Full text and comments »

  • Vote: I like it
  • -20
  • Vote: I do not like it