Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int n;
  5. long long d;
  6. cin >> n >> d;
  7. pair <long long,long long> arr[n];
  8. long long max = 0;
  9. for(int i = 0; i < n; i++){
  10. pair <int,int> a;
  11. cin >> a.first >> a.second;
  12. arr[i] = a;
  13. }
  14. sort(arr,arr+n);
  15. for(int i = 0; i < n; i++){
  16. long long cont = arr[i].second;
  17. for(int j = i+1; j < n; j++){
  18. if(arr[j].first - arr[i].first < d){
  19. cont += arr[j].second;
  20. }
  21. }
  22. if(cont > max){
  23. max = cont;
  24. }
  25. }
  26. cout << max;
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement