fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define endl "\n"
  4. #define ll long long
  5. #define file1 freopen(s, "r", stdin);
  6. #define file2 freopen(s, "w", stdout);
  7. #define all(v) ((v).begin()), ((v).end())
  8. #define rall(v) ((v).rbegin()), ((v).rend())
  9. #define fast ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
  10. const double pi = acos(-1.0);//3.14
  11. //cout << fixed << setprecision(9);
  12. int32_t main() {
  13. // Oh,here we go again ..
  14. fast;
  15. int t;
  16. cin>>t;
  17. while (t--)
  18. {
  19. int n;
  20. cin>>n;
  21. vector<int>a(n);
  22. bool ok=0;
  23. ll sum=0;
  24. for (int i = 0; i < n; ++i) {
  25. cin >> a[i];
  26. sum+=a[i];
  27. if(a[i]<0)
  28. ok=1;
  29. }
  30. int m;
  31. cin>>m;
  32. vector<int>b(m);
  33. ll x=0;
  34. for (int i = 0; i < m; ++i) {
  35. cin >> b[i];
  36. if(b[i]>0)
  37. sum+=b[i],x+=b[i];
  38. }
  39. if(ok==0)
  40. cout<<sum<<endl;
  41. else
  42. {
  43. int xx=0,yy=0;
  44. for (int i = 0; i < n; ++i) {
  45. if(a[i]<0)
  46. break;
  47. xx+=a[i];
  48. }
  49. for (int i = n-1; i >=0 ; --i) {
  50. if(a[i]<0)
  51. break;
  52. yy+=a[i];
  53. }
  54. cout<<max(xx,yy)+x<<endl;
  55. }
  56. }
  57. }
Success #stdin #stdout 0.01s 5520KB
stdin
Standard input is empty
stdout
Standard output is empty