fork download
  1. ////Time too shall pass, remain to expect hope<3
  2. #include <bits/stdc++.h>
  3. #define ll long long
  4. #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. FAST;
  10. ll t;
  11. cin>>t;
  12. while(t--) {
  13. ll n,c = 0,temp_sum=0,total_sum=0, ans = INT_MIN;
  14. cin>>n;
  15. vector < ll > v(n);
  16. for(ll i = 0 ; i < n ; i++) {
  17. cin>>v[i];
  18. total_sum+=v[i];
  19. }
  20. for(ll i = 0 ; i < (n-1); i++) {
  21. temp_sum = total_sum;
  22.  
  23. temp_sum -= v[i];
  24. temp_sum -= v[i+1];
  25.  
  26. temp_sum += -v[i];
  27. temp_sum += -v[i+1];
  28.  
  29. if(temp_sum > ans)
  30. ans = temp_sum;
  31. }
  32. cout<<ans<<endl;
  33. }
  34.  
  35. return 0;
  36. }
  37.  
  38. //OH MY HOPE ALLAH...
Success #stdin #stdout 0.01s 5396KB
stdin
4
5
-1 1 1 -1 -1
5
1 1 -1 -1 -1
2
1 1
4
1 -1 -1 1
stdout
3
3
-2
4