- Dashboard
- Data Structures
- Stacks
- Largest Rectangle
-
-
#include <vector> #include <iostream> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; vector<int> height(n); for (int i = 0; i < n; ++ i) { cin >> height[i]; } int prev, next; long long maxi = 0, temp; for (int i = 0; i < n; ++ i) { temp = height[i]; prev = i - 1; next = i + 1; while (prev >= 0 && height[prev] >= height[i]) { temp += height[i]; -- prev; } while (next < n && height[next] >= height[i]) { temp += height[i]; ++ next; } maxi = temp > maxi ? temp : maxi; } cout << maxi << endl; return 0; }
-
C++ HackerRank|Largest Rectangle
最新推荐文章于 2021-07-28 10:24:42 发布