Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Kei
Problemset: ปริมาตรน้ำท่วม
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-08 17:10:26
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
void solve(){
int n,max=0; cin >> n;
int markedcol=-1;
bool marked=false;
int amtwtr=0;
//colh's
vector<int> v(n);
for(int& x : v){
cin >> x;
if(x>max) max=x;
}
for(int i=max;i>=0;i--){
for(int j=0;j<n;j++){
if(v[j]>=i && marked==false){
markedcol = j;
marked=true;
}
else if(v[j]>=i && marked == true){
amtwtr+=j-markedcol-1;
markedcol=j;
}
}
marked=false;
}
cout << amtwtr;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}