AC 8 个点
#include <bits/stdc++.h>
#define L(i, a, b) for(int i = (a); i <= (b); i++)
#define R(i, a, b) for(int i = (a); i >= (b); i--)
#define pii pair<int, int>
#define ll long long
#define vi vector<int>
using namespace std;
const int N = 1e6 + 10;
int p[N], ans, n, e[N], se[N];
int find1(int x, int s) {
R(i, s, 1) if(p[i] > x) return i;
return 0;
}
int find2(int x, int s) {
L(i, s, n) if(p[i] > x) return i;
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
L(i, 1, n) cin >> p[i] >> e[i];
int x = 0, y = 0;
L(i, 1, n) {
x = find1(p[i], i-1);
y = find2(p[i], i+1);
se[x] += e[i];
se[y] += e[i];
}
cout << *max_element(se+1, se+n+1);
return 0;
}
qwq