还是用单调栈求子矩形的最大值,不能写这种题了,都是写了好几个都是记忆了,等几天再写下一道,检验一下自己是不是真的掌握了,
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
int main() {
int n;
while (cin >> n && n != -1) {
stack<pa> st;
int ans = 0;
for (int i = 0; i < n; i++) {
int w, h;
scanf("%d %d", &w, &h);
if (!i) st.push(make_pair(h, w));
else {
if (h >= st.top().fi) st.push(make_pair(h, w));
else {
int tmp = 0;
while (!st.empty() && h < st.top().fi) {
pa p = st.top(); st.pop();
tmp += p.se;
ans = max(ans, tmp * p.fi);
}
st.push(make_pair(h, tmp + w));
}
}
}
int tmp = 0;
while (!st.empty()) {
pa p = st.top(); st.pop();
tmp += p.se;
ans = max(ans, tmp * p.fi);
}
cout << ans << endl;
}
return 0;
}