File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ typedef long long ll;
5
+ typedef pair<int , int > pii;
6
+ #define mp (a, b ) make_pair(a, b)
7
+
8
+ #define X first
9
+ #define Y second
10
+
11
+ int i, n, k;
12
+ vector<pii> field;
13
+
14
+ int main () {
15
+ ios::sync_with_stdio (false ); cin.tie (NULL );
16
+
17
+ cin>>n>>k;
18
+ for (i=0 ;i<n;++i){
19
+ int a, b;
20
+ cin>>a>>b;
21
+ field.push_back (mp (b, a));
22
+ }
23
+
24
+ sort (field.begin (), field.end ());
25
+
26
+ ll cur=field[0 ].Y , ans=cur;
27
+ auto s=field.begin (), e=field.begin (); // both inclusive
28
+
29
+ while (s != field.end ()){
30
+ if (e->X - s->X > 2 *k){
31
+ cur -= s->Y ;
32
+ s++;
33
+ } else if (e != field.end ()){
34
+ e++;
35
+ cur += e->Y ;
36
+ } else break ;
37
+
38
+ if (e->X - s->X <= 2 *k) ans = max (ans, cur);
39
+ }
40
+
41
+ cout<<ans<<" \n " ;
42
+ return 0 ;
43
+ }
You can’t perform that action at this time.
0 commit comments