fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define dd double
  5. #define ld long double
  6. #define pi 3.14159265359
  7. #define ull unsigned long long
  8. #define yes cout<<"YES\n"
  9. #define no cout<<"NO\n"
  10. #define el "\n"
  11. #define Arwa ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  12. #define fix(x) cout<<fixed<<setprecision(x)
  13. ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
  14. ll lcm(int a,int b) {return a/gcd(a,b)*b;}
  15. bool prime(ll n)
  16. {
  17. if(n==2) return true;
  18. if(n%2==0||n==1) return false;
  19. else { for(ll i=3; i*i<=n; i+=2) {if(n%i==0) return false;}}return true;
  20. }
  21. //here we go again
  22. int main()
  23. {
  24. Arwa
  25. int t=1;
  26. cin>>t;
  27. while(t--)
  28. {
  29. int n;
  30. cin>>n;
  31. int arr[n];
  32. for(int i=0;i<n;i++)
  33. cin>>arr[i];
  34. ll sum=0;
  35. for(int i=0;i<n;i++)
  36. {
  37. if(sum+arr[i]>abs(sum+arr[i]))
  38. sum=sum+arr[i];
  39. else sum=abs(sum+arr[i]);
  40. }
  41. cout<<sum<<el;
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1288648734