Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n;
- long long d;
- cin >> n >> d;
- pair <long long,long long> arr[n];
- long long max = 0;
- for(int i = 0; i < n; i++){
- pair <int,int> a;
- cin >> a.first >> a.second;
- arr[i] = a;
- }
- sort(arr,arr+n);
- for(int i = 0; i < n; i++){
- long long cont = arr[i].second;
- for(int j = i+1; j < n; j++){
- if(arr[j].first - arr[i].first < d){
- cont += arr[j].second;
- }
- }
- if(cont > max){
- max = cont;
- }
- }
- cout << max;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement