#include <iostream>
using namespace std;
int Volume(int* _Array)
{
int lv_Volume = 0;
auto lv_Max = _Array[0];
for(int lv_SmallVolume = 0; *_Array; ++_Array)
if(*_Array >= lv_Max)
{
lv_Max = *_Array;
lv_Volume += lv_SmallVolume;
lv_SmallVolume = 0;
}
else
lv_SmallVolume += lv_Max - *_Array;
return lv_Volume;
}
int main()
{
int lv_Array[] = {2,5,1,3,1,2,1,7,7,6};
auto lv_Volume = Volume(lv_Array);
if( lv_Volume == 17)
cout << "PASS";
else
cout << "FAIL";
return 0;
}
CiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBWb2x1bWUoaW50KiBfQXJyYXkpCnsKCWludCBsdl9Wb2x1bWUgPSAwOwoKCWF1dG8gbHZfTWF4ID0gX0FycmF5WzBdOwoJZm9yKGludCBsdl9TbWFsbFZvbHVtZSA9IDA7ICpfQXJyYXk7ICsrX0FycmF5KQoJCWlmKCpfQXJyYXkgPj0gbHZfTWF4KQoJCXsKCQkJbHZfTWF4ID0gKl9BcnJheTsKCQkJbHZfVm9sdW1lICs9IGx2X1NtYWxsVm9sdW1lOwoJCQlsdl9TbWFsbFZvbHVtZSA9IDA7CgkJfQoJCWVsc2UKCQkJbHZfU21hbGxWb2x1bWUgKz0gbHZfTWF4IC0gKl9BcnJheTsKCQoJcmV0dXJuIGx2X1ZvbHVtZTsKfQoKaW50IG1haW4oKSAKewoJaW50IGx2X0FycmF5W10gPSB7Miw1LDEsMywxLDIsMSw3LDcsNn07CglhdXRvIGx2X1ZvbHVtZSA9IFZvbHVtZShsdl9BcnJheSk7CgkKCWlmKCBsdl9Wb2x1bWUgPT0gMTcpCgkJY291dCA8PCAiUEFTUyI7CgllbHNlCgkJY291dCA8PCAiRkFJTCI7CgkKCXJldHVybiAwOwp9