Advertisement
7oSkaaa

Kefa and Company

Aug 11th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define read(vec, n) for(int i = 0 ; i < n && cin >> vec[i] ; i++);
  5. #define print(v, template) copy(all(v), ostream_iterator <template> (cout, " "));
  6. #define read_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> nums[i][j]; j++);
  7. #define loop(a, b, c) for(int i = a ; i < (b); i += c)
  8. #define all(vec) vec.begin(),vec.end()
  9. #define rall(vec) vec.rbegin(),vec.rend()
  10. #define Vector vector <int>
  11. #define Map map <int,int>
  12. #define Set set <int>
  13. #define Pair pair <int,int>
  14. #define ll long long
  15. #define ull unsigned long long
  16. #define Mod 1000000007
  17. #define PI 3.14159
  18.  
  19. void Code_Crush(){
  20.   ios_base::sync_with_stdio(false);   cin.tie(nullptr);   cout.tie(nullptr);
  21. #ifndef ONLINE_JUDGE
  22.   freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  23. #endif
  24. }
  25.  
  26. int main(){
  27.     Code_Crush();
  28.     int n, d, i = 0;
  29.     ll Max_friendship = INT_MIN, Max_friend = 0;
  30.     cin >> n >> d;
  31.     vector <pair<int, int>> companies(n);
  32.     for(auto& [f, s] : companies) cin >> f >> s;
  33.     sort(all(companies));
  34.     for(int i = 0, j = 0; i < n; i++){
  35.       Max_friend += companies[i].second;
  36.       while(companies[i].first - companies[j].first >= d) Max_friend -= companies[j++].second;
  37.       Max_friendship = max(Max_friend, Max_friendship);
  38.     }
  39.     cout << Max_friendship;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement