# 注：本题只需要提交标记为修改部分之间的代码，请按照C++方式提交。

+15，-2,+5,-1,+10,-3 ,-2 ,+12 , +4 ,-5 ,-6

#include <iostream>
using namespace std;
int main()
{
int maxDistance=0,relative,sum=0;
int i,n;
cin>>n;
for(i=0; i<n; i++)
{
cin>>relative;
sum+=relative;
if(sum>0)
{
if(maxDistance<sum)
maxDistance=sum;
}
else
{
/*
请填写该部分代码
*/

}
}
cout<<maxDistance<<endl;
return 0;
}

n 和 n 条行走记录

``````11
+15 -2 +5 -1 +10 -3 -2 +12 +4 -5 -6``````

``````38
``````

``````
#include <iostream>
using namespace std;
int main()
{
int maxDistance=0,relative,sum=0;
int i,n;
cin>>n;
for(i=0; i<n; i++)
{
cin>>relative;
sum+=relative;
if(sum>0)
{
if(maxDistance<sum)
maxDistance=sum;
}
else
{
if(-sum>maxDistance)
maxDistance=-sum;
}
}
cout<<maxDistance<<endl;
return 0;
}
``````

``````
#include <iostream>
using namespace std;
int main()
{
int maxDistance=0,relative,sum=0;
int i,n;
cin>>n;
for(i=0; i<n; i++)
{
cin>>relative;
sum+=relative;
if(sum>0)
{
if(maxDistance<sum)
maxDistance=sum;
}
else
{
if(maxDistance<-sum)
maxDistance=-sum;
}
}
cout<<maxDistance<<endl;
return 0;
}
``````