-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10025.cpp
More file actions
38 lines (33 loc) · 769 Bytes
/
10025.cpp
File metadata and controls
38 lines (33 loc) · 769 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
using ll = long long;
#define MAXN 100050
ll N,K,gi[1000005],xi[MAXN],sum[1000005];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> N >> K;
for(int i=0 ; i<N ; i++){
ll x,g;
cin >> g >> x;
gi[x] = g;
}
sum[0] = gi[0];
for(int i=1 ; i<=1000000 ; i++){
sum[i] = sum[i-1] + gi[i];
}
ll ans=0;
for(int i=0 ; i<=1000000 ; i++){
if(i<K){
ans = max(ans, sum[i]);
}else if(K<=i && i<=1000000-K){
ans = max(ans, sum[i+K]-sum[i-K-1]);
}else {
ans = max(ans, sum[i] - sum[i-K-1]);
}
}
cout << ans;
}