Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Sol2468

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-16 01:52:01

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

int n ;
vector<int> high ;
vector<string> arr ;

int main(){
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n ;
    int mx=-1 ;
    for(int i=0 ; i<n ; i++){
        int in1 ;
        cin >> in1 ;
        mx = max(mx,in1) ;
        high.push_back(in1) ;
    }
    string wall(mx+1,'-') ;
    arr.push_back(wall) ;
    for(int i=0 ; i<n ; i++){
        string temp1(high[i]+1,'O') ;
        string temp2(mx-high[i],'.') ;
        arr.push_back(temp1+temp2) ;
    }
    // arr.push_back(wall) ;
    // for(string i : arr){
    //     cout << i << "\n" ;
    // }
    int ans=0 ;
    for(int i=1 ; i<arr[0].size() ; i++){
        bool ready = false ;
        int temp=0 ;
        for(int j=1 ; j<arr.size() ; j++){
            if(arr[j][i]=='O'){
                if(ready==true){
                   ans += temp ;
                   temp = 0 ;
                } 
                ready = true ;
            }else if(arr[j][i]=='.'){
                if(ready==true) temp++ ;
            }
        }
    }
    cout << ans ;
    return 0 ;
}