Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: rice_ot
Problemset: ปริมาตรน้ำท่วม
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-24 20:55:26
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
vector<int> num(n);
for(auto& i : num) cin>>i;
int lmax = num[0], rmax = num[n-1];
int start = 1, end = n-2;
int res = 0;
while(start <= end){
if(lmax <= rmax){
if(lmax - num[start] >= 0) res+=lmax-num[start];
else lmax = num[start];
start++;
}
else if(lmax > rmax){
if(rmax - num[end] >= 0) res+=rmax-num[end];
else rmax = num[end];
end--;
}
}
cout<<res;
}