Uva 12640 Solution

 #include<bits/stdc++.h>
using namespace std;

int maximum(vector<int>v)
{
int f = 0, t = 0;

for(int i=0;i<v.size();i++)
{
t += v[i];

if(t > f)
f = t;

if(t < 0)
t = 0;
}

return f;
}

int main()
{
string s;
while(getline(cin, s))
{
int w;
vector<int>v;

stringstream st(s);

while(st >> w)
v.push_back(w);

cout << maximum(v) << "\n";
}

return 0;
}

Comments