#include <iostream>
using namespace std;
int max(int a[],int t, int n)
{
int m = a[t];
for(int i = t+1; i< n; i++)
{
if(a[i]>m)
m = a[i];
}
return m;
}
int main()
{
int tc, T,n, a[31], tk;
int mua, ban, imua, iban;
freopen("input.txt", "r", stdin);
cin >>T;
for(tc = 1; tc <= T; tc++)
{
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
mua = 0; ban = 0; imua=0; iban=0;
for(int i = 0; i < n; i++)
{
tk = max(a,i,n);
if(a[i] <tk)
{
mua = mua + a[i];
imua++;
}
else{
ban = ban+imua*a[i] - mua;
iban++;
imua =0;
mua=0;
}
}
cout <<"#"<<tc<<" "<< ban << endl;
}
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.