bckang92   4달 전

#include <iostream>
using namespace std;

int main(){
int loop;
cin >> loop;
for (int i = 0; i < loop; i++){
int day;
cin >> day;
int *arr = new int[day];
for (int j = 0; j < day; j++){
cin >> arr[j];
}
int *narr = new int[day];
int most = 0;
narr[day - 1] = arr[day - 1];
most = arr[day - 1];
for (int i = day - 2; i >= 0; i--){
if (arr[i] < most){
narr[i] = most;
}
else if (arr[i] == most){
narr[i] = most;
}
else{
narr[i] = arr[i];
most = arr[i];
}
}

int result = 0;
for (int r = 0; r < day; r++){
result = result + (narr[r] - arr[r]);
}
cout << result << endl;
}

}

댓글을 작성하려면 로그인해야 합니다.