fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int prevAndNext(int *heights,int position,int size)
  4. {
  5. int j,count=1;
  6. for (j = position - 1; j >= 0; j--)
  7. if (heights[position] <= heights[j])
  8. count++;
  9. else
  10. break;
  11. for (j = position+1; j < size;j++)
  12. if (heights[position] <= heights[j])
  13. count++;
  14. else
  15. break;
  16. return count;
  17. }
  18. int main()
  19. {
  20. int i,size,max,temp, *heights;
  21. scanf("%d", &size);
  22. if (size <= 0)
  23. return 0;
  24. heights = (int*)malloc(sizeof(int)*size);
  25. for (i = 0; i < size;i++)
  26. {
  27. scanf("%d", &heights[i]);
  28. }
  29. max = prevAndNext(heights, 0, size)*heights[0];
  30. for (i = 1; i < size; i++)
  31. {
  32. if (heights[i] == heights[i - 1])
  33. continue;
  34. temp = prevAndNext(heights, i, size)*heights[i];
  35. if (max < temp)
  36. max = temp;
  37. }
  38. printf("%d\n", max);
  39. free(heights);
  40. return 0;
  41. }
Success #stdin #stdout 0s 9416KB
stdin
4 80 80 78 60
stdout
240