Sofdor Ali and Histogram

Limits: 1s, 512 MB

The Great Sofdor Ali is now interested in competitive programming. Seeing this, his friend and also a renowned scientist Anik Lumba gave him a problem. The problem statement is simple. You have a non-decreasing histogram. You have to find the area of largest rectangle contained within the histogram. For example, in the histogram below, where the 6 bars have heights 1 2 2 4 5 7, the area colored in red is the largest rectangle contained by the histogram. The area of this rectangle is 12.

This is a companion discussion topic for the original entry at

is there diagram require??

1 Like

Thanks for reporting this. The statement has been fixed.

what is the problem here? anyone can help?
got wa in 13no. test case…


using namespace std;

int main() {
int T,i;
int N;
unsigned long long int height[100000];
cin >> T;
for(i = 1; i <= T; i++) {
cin >> N;
for(int j = 0, k = N; j < N; j++) {
cin >> height[j];
height[j] = height[j] * k;
for(int l = 1; l < N; l++) {
if(height[0] < height[l]) {
height[0] = height[l];
printf(“Case %d: %llu\n”,i,height[0]);
return 0;