fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;
  7. cin>>t;
  8. while(t--){
  9. int n;
  10. cin>>n;
  11. long long a[n],b[n];
  12. for(int i=0;i<n;i++){
  13. cin>>a[i];
  14. }
  15.  
  16. b[0] = a[0];
  17. for(int i=1;i<n;i++){
  18.  
  19. if(b[i-1] > a[i]){
  20. b[i] = a[i];
  21. } else {
  22. b[i] = b[i-1];
  23. }
  24. //cout<<b[i]<<endl;
  25. }
  26.  
  27. int sum =0;
  28. for(int i=0;i<n;i++){
  29. sum += b[i];
  30. }
  31. cout<<sum;
  32.  
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.02s 4348KB
stdin
1
9
3 4 2 1 8 1 9 2 5
stdout
14