Submission
Status:
----------
Subtask/Task Score:
0/100
Score: 0
User: nattawin
Problemset: ปริมาตรน้ำท่วม
Language: cpp
Time: 0.002 second
Submitted On: 2026-10-05 13:37:35
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,flood;
cin>>n;
vector <int> a(10001);
for(int i = 0 ; i < n ; i++)
{
cin>>a[i];
}
int LL = a[0] , RR = a[n-1] , j = 1 , l = n-2;
while(j<n)
{
if(LL<=RR)
{
if(LL>=a[j])
{
flood+=LL-a[j];
cout<<LL<<endl;
cout<<LL<<" - "<<a[j]<<" = "<<flood<<endl;
}
else if(LL<a[j])
{
LL=a[j];
}
j++;
}
else if(RR<LL)
{
if(RR>=a[l])
{
flood+=RR-a[l];
cout<<RR<<endl;
cout<<RR<<" - "<<a[l]<<" = "<<flood<<endl;
}
else if(RR<a[l])
{
RR=a[l];
}
l--;
n--;
}
}
cout<<flood<<endl;
}