-
Notifications
You must be signed in to change notification settings - Fork 0
/
11501.cpp
43 lines (41 loc) · 977 Bytes
/
11501.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;
int main(){
int T; cin >> T;
for(int i=0; i<T; i++){
vector<int> ju;
vector<int> mx;
int re=0;
int N; cin >> N;
for(int j=0; j<N; j++){
int a;cin>>a;
ju.push_back(a);
}
int m=ju[0];
mx.push_back(0);
int cnt=0;
for(int j=1; j<ju.size();j++){
if(ju[j]>=m){
mx[cnt]=j;
}else{
if(ju[mx[cnt]]<m){
mx[cnt]=j-1;
mx.push_back(j);
}else{
mx.push_back(j);aaa
}
}
m=ju[j];
cnt++;
}
int nx=0;
for(int j=0;j<mx.size();j++){
for(int k=nx;k<=mx[j];k++){
if(ju[mx[j]]-ju[k]>=0)
re=re+ju[mx[j]]-ju[k];
}
nx=mx[j];
}
cout << re << "\n";
}
}