Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: robgornpeunpadpairoundnigumaipadnea
Problemset: ปริมาตรน้ำท่วม
Language: cpp
Time: 0.002 second
Submitted On: 2026-02-24 23:28:18
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n;cin>>n;
vector<int> v(n);for(auto&i :v)cin>>i;
int l=0,lmax=v[0];
int r=n-1,rmax=v[n-1];
int ans = 0;
while(l<r){
if(lmax < rmax){
ans += lmax-v[l];
l++;
lmax = max(lmax,v[l]);
}
else{
ans += rmax-v[r];
r--;
rmax = max(rmax,v[r]);
}
}
cout << ans;
}