Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define read(vec, n) for(int i = 0 ; i < n && cin >> vec[i] ; i++);
- #define print(v, template) copy(all(v), ostream_iterator <template> (cout, " "));
- #define read_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> nums[i][j]; j++);
- #define loop(a, b, c) for(int i = a ; i < (b); i += c)
- #define all(vec) vec.begin(),vec.end()
- #define rall(vec) vec.rbegin(),vec.rend()
- #define Vector vector <int>
- #define Map map <int,int>
- #define Set set <int>
- #define Pair pair <int,int>
- #define ll long long
- #define ull unsigned long long
- #define Mod 1000000007
- #define PI 3.14159
- void Code_Crush(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int main(){
- Code_Crush();
- int n, d, i = 0;
- ll Max_friendship = INT_MIN, Max_friend = 0;
- cin >> n >> d;
- vector <pair<int, int>> companies(n);
- for(auto& [f, s] : companies) cin >> f >> s;
- sort(all(companies));
- for(int i = 0, j = 0; i < n; i++){
- Max_friend += companies[i].second;
- while(companies[i].first - companies[j].first >= d) Max_friend -= companies[j++].second;
- Max_friendship = max(Max_friend, Max_friendship);
- }
- cout << Max_friendship;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement