Skip to content

Commit 6ca6e28

Browse files
committedJun 26, 2022
solved 10025
1 parent 0e8106c commit 6ca6e28

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
 

‎10000/10025/10025.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)
Please sign in to comment.