-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKefaandCompany.cpp
More file actions
59 lines (52 loc) · 952 Bytes
/
KefaandCompany.cpp
File metadata and controls
59 lines (52 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
AUTHOR: Antarikshya Mitra
TIME:
PROBLEM NO:- Kefa and Company Div2 B
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
bool cmp(const vector<int> &a,const vector<int> &b)
{
if(a[0]<b[0]) return true;
else return false;
}
void solve(vector<vector<int>> &arr,int d)
{
int n = arr.size();
sort(arr.begin(),arr.end(),cmp);
int l = 0;
int sum = 0;
int ans = 0;
for(int r=0;r<n;r++)
{
sum+=arr[r][1];
while(l<r && arr[r][0] - arr[l][0] >= d)
{
sum-=arr[l][1];
l++;
}
ans = max(ans,sum);
}
cout<<ans<<endl;
return;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n,d;
cin>>n>>d;
vector<vector<int>> arr(n);
for(int i=0;i<n;i++)
{
int money,points;
cin>>money>>points;
arr[i] = {money, points};
}
solve(arr,d);
return 0;
}