Submission

Status:

PPPP-PPPPP

Subtask/Task Score:

90/100

Score: 90

User: Kittipon

Problemset: ปริมาตรน้ำท่วม

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-05 11:02:00

#include <bits/stdc++.h>
using namespace std;

int n,h[10005];
int temph,tempwater[100005],water;
int mxh;

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> h[i];
        mxh = max(mxh,h[i]);
    }
    temph = h[1];
    for(int i = 2;i <= n;i++){
        if(temph < h[i]){
            temph = h[i];
            //continue;
        } 
        for(int j = 1;j <= mxh;j++){
            if(j - h[i] > 0) tempwater[j] += j - h[i];
        }
        if(h[i+1] > temph){
          water += tempwater[temph];  
          memset(tempwater,0,sizeof(tempwater));
        }
        if(i == n){
            water += tempwater[h[i]];
        } 
    }
    cout << water;
}

/*


#
#  #
## #
####
####
*/