tanasaradu

Untitled

Oct 25th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("ssm.in");
  4. ofstream fout("ssm.out");
  5. int main()
  6. {
  7. int n,x;
  8. fin>>n>>x;
  9. int bg,ed,poz;
  10. long long s,smax;
  11. s=smax=x;
  12. bg=ed=poz=1;
  13. if(s<0)
  14. {
  15. s=0;
  16. poz=2;
  17. }
  18. for(int i=2;i<=n;i++)
  19. {
  20. fin>>x;
  21. s+=x;
  22. if(smax<s)
  23. {
  24. smax=s;
  25. bg=poz;
  26. ed=i;
  27. }
  28. if(s<0)
  29. {
  30. s=0;
  31. poz=i+1;
  32. }
  33. }
  34. fout<<smax<<" "<<bg<<" "<<ed<<"\n";
  35. fin.close();
  36. fout.close();
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment