1 #include <iostream> 2 #include <cstdlib> 3 using namespace std; 4 5 int main() 6 { 7 int n = 0; 8 cin >> n; 9 while (n > 0) 10 { 11 int maxProfit = -1000; 12 int currProfit = 0; 13 int amount = 0; 14 15 for (int i = 0; i < n; i++) 16 { 17 cin >> amount; 18 currProfit += amount; 19 maxProfit = max(maxProfit, currProfit); 20 21 currProfit = max(currProfit, 0); 22 23 } 24 cout << maxProfit << endl; 25 cin >> n; 26 } 27 }