Guest User

Untitled

a guest
Oct 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. typedef long long ll;
  2.  
  3. const ld eps = 0.000000001;
  4. const ld pi = 3.14159265358979323;
  5.  
  6. int main(int argc, char **argv)
  7. {
  8. ios_base::sync_with_stdio(false);
  9. #ifndef LOCAL
  10. freopen("input.txt", "r", stdin);
  11. freopen("output.txt", "w", stdout);
  12. #endif // LOCAL
  13.  
  14. int n;
  15. cin >> n;
  16.  
  17. vector<ll> a(n);
  18. for(auto &i : a) {
  19. cin >> i;
  20. }
  21.  
  22. ll ans = a[0], sum = 0;
  23. ll l = 0, r = 0, pred_l = -1;
  24.  
  25. for(int i = 0; i < a.size(); ++i) {
  26. sum += a[i];
  27.  
  28. if(sum > ans) {
  29. ans = sum;
  30. l = pred_l + 1;
  31. r = i;
  32. }
  33.  
  34. if(sum < 0) {
  35. sum = 0;
  36. pred_l = r;
  37. }
  38. }
  39.  
  40. cout << l + 1 << " " << r + 1 << " " << ans << endl;
  41. return 0;
  42. }
Add Comment
Please, Sign In to add comment