标签:idt typedef eof string des image miss ogr lld
Largest Rectangle in a Histogram
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 21708 | Accepted: 7003 |
Description
Input
Output
Sample Input
7 2 1 4 5 1 3 3 4 1000 1000 1000 1000 0
Sample Output
8 4000
Hint
Source
#include <stdio.h> #include <string.h> typedef long long LL; const int maxn=1e5+5; LL a[maxn]; int s[maxn]; int L[maxn]; int R[maxn]; int main() { int n; while(scanf("%d",&n),n) { memset(s, 0, sizeof(s)); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } int top = 0; a[0] = -1; for (int i = 1; i <= n; i++) { while (top && a[i] <= a[s[top]]) { top--; } L[i] = s[top]; s[++top] = i; } top = 0; s[top++] = n + 1; a[n + 1] = -1; for (int i = n + 1; i >= 1; i--) { while (top && a[i] <= a[s[top]]) { top--; } R[i] = s[top]; s[++top] = i; } LL ans = 0; for (int i = 1; i <= n; i++) { LL t = (R[i] - L[i] - 1) * a[i]; if (ans < t) ans = t; } printf("%lld\n", ans); } return 0; }
POJ 2559 Largest Rectangle in a Histogram
标签:idt typedef eof string des image miss ogr lld
原文地址:http://www.cnblogs.com/BobHuang/p/6835269.html