fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int add(int* tab, int beg, int end);
  6.  
  7. int main()
  8. {
  9. int result;
  10. int max=0;
  11. int cities;
  12. cin >> cities;
  13. int *profit = new int[cities];
  14.  
  15. for (int i = 0; i < cities; i++)
  16. {
  17. cin >> profit[i];
  18. }
  19.  
  20. for (int i = 0; i < cities; i++)
  21. {
  22. for (int n = i; n < cities; n++)
  23. {
  24. result = add(profit, i, n);
  25. if (result > max) max = result;
  26.  
  27. }
  28. }
  29. delete[] profit;
  30.  
  31. cout << max;
  32. return 0;
  33. }
  34.  
  35. int add(int* tab, int beg, int end)
  36. {
  37. int result = 0;
  38. for (int i = beg; i <= end; i++)
  39. {
  40. result += tab[i];
  41. }
  42. return result;
  43. }
Time limit exceeded #stdin #stdout 5s 528896KB
stdin
Standard input is empty
stdout
Standard output is empty