Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main(){
  6. int currentmax =0;
  7. int maxsum = 0;
  8. int n;
  9. cin >> n;
  10. int current[n] = {0};
  11. int arr[n];
  12. bool secondtime[n][n] = {false};
  13. for (int i =0; i <n; i++){
  14. cin >> arr[i];
  15. }
  16. for (int i = 0; i < n; i++){
  17. for (int k = 0; k < 2; k++){
  18.  
  19. for (int j = i; j < n - i; j++){
  20. current[i] = current[i] + arr[j];
  21. if (current[i] < 0){
  22. current[i] = 0;
  23. }
  24. if (current[i] > currentmax){
  25. currentmax = current[i];
  26. }
  27. if (maxsum < currentmax){
  28. maxsum = currentmax;
  29. }
  30. for (int j = 0; j < i; j++){
  31. current[i] = current[i] + arr[j];
  32. if (current[i] < 0){
  33. current[i] = 0;
  34. }
  35. if (current[i] > currentmax){
  36. currentmax = current[i];
  37. }
  38. if (maxsum < currentmax){
  39. maxsum = currentmax;
  40. }
  41. }
  42. }
  43. }
  44. }
  45. cout << maxsum << endl;
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement