You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 1000010;
|
|
|
|
|
int n;
|
|
|
|
|
int a[N], b[N]; //高度与能力值
|
|
|
|
|
int s[N];//结果数组
|
|
|
|
|
int ans; //最大值
|
|
|
|
|
|
|
|
|
|
//用数组模拟栈,每一个栈内的元素,都是需要找到“比自己高度小的,离自己最近”的发射塔,才能享受它带来的能量值。
|
|
|
|
|
int stk[N]; //内容:序号
|
|
|
|
|
int tt; //指针,默认是0
|
|
|
|
|
|
|
|
|
|
void add(int i) {
|
|
|
|
|
//把栈顶高度比自己小的出栈,这样的是不能享受i个发射塔带来的能量滴~
|
|
|
|
|
while (tt && a[i] > a[stk[tt]]) tt--;
|
|
|
|
|
//如果找着了一个高度比自己大的发射塔,那么,这个位置的发射塔将享受i个发射塔带来的能量。
|
|
|
|
|
s[stk[tt]] += b[i];
|
|
|
|
|
//把自己入栈,等待其它人给自己带来能量,enjoy!
|
|
|
|
|
stk[++tt] = i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
//输入
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
|
|
|
|
|
|
|
|
|
|
//从左向右扫一遍
|
|
|
|
|
for (int i = 1; i <= n; i++) add(i);
|
|
|
|
|
|
|
|
|
|
//还原指针,清空栈
|
|
|
|
|
tt = 0;
|
|
|
|
|
//从右向左扫一遍
|
|
|
|
|
for (int i = n; i >= 1; i--) add(i);
|
|
|
|
|
|
|
|
|
|
//找出结果
|
|
|
|
|
for (int i = 1; i <= n; i++) ans = max(ans, s[i]);
|
|
|
|
|
|
|
|
|
|
//输出
|
|
|
|
|
printf("%d", ans);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|