fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. int main() {
  6. ll t,i;cin>>t;
  7. while(t--){
  8. ll n,i;cin>>n;
  9. vector<int>v(n);
  10. for(i=0;i<n;i++){
  11. cin>>v[i];
  12. }
  13. int ms=INT_MIN,me=0,a=0,b=0;
  14. for(i=0;i<n;i++){
  15. me+=v[i];
  16. if(me==0){
  17. a=i;
  18. }
  19. if(ms<me){
  20. ms=me;
  21. b=i;
  22. }
  23. if(me<0){
  24. me=0;
  25. }
  26. }
  27. cout<<ms<<" "<<a<<" "<<b<<"\n";
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5460KB
stdin
3
9
-24 0 28 28 55 -31 -27 -45 -24 
10
40 5 39 45 31 -44 73 -16 -31 27 
7
57 18 -14 17 31 16 -16 
stdout
111 1 4
189 0 6
125 0 5