Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: pann
Problemset: ปริมาตรน้ำท่วม
Language: cpp
Time: 0.003 second
Submitted On: 2026-10-11 03:16:02
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> v;
int max = 0;
for (int i = 0; i < n; i++){
int x;
cin >> x;
v.push_back(x);
if (x > v[max]) max = i;
}
int a = 0, l = 0, total = 0;
while (true){
if (v[a] >= v[l]){
for (int i = l; i < a; i++){
total += v[l] - v[i];
}
l = a;
}
if (a == max) break;
a++;
}
int b = n-1, r = n-1;
while (true){
if (v[b] >= v[r]){
for (int i = r; i > b; i--){
total += v[r] - v[i];
}
r = b;
}
if (b == max) break;
b--;
}
cout << total;
return 0;
}