fork download
  1. #include <stdio.h>
  2. int main()
  3. {
  4. int t;
  5. scanf("%d",&t);
  6. while(t--)
  7. {
  8. long int x;
  9. int i;
  10. scanf("%d",&x);
  11. long int a[x];
  12. for(i=0;i<x;i++)
  13. {
  14. scanf("%ld",&a[i]);
  15. }
  16. long int min=a[0],max=0;
  17. for(i=0;i<x;i++)
  18. {
  19. if(a[i]<min)
  20. min=a[i];
  21. max=max+(a[i]-min);
  22. }
  23. printf("%ld\n",max);
  24. }
  25. return 0;
  26.  
  27.  
  28. }
  29.  
  30.  
Success #stdin #stdout 0.01s 5492KB
stdin
1
6
1000 1000 1000 1000 1000 5
stdout
0