Pagini recente » Cod sursa (job #2720823) | Cod sursa (job #1139644) | Cod sursa (job #1739493) | Cod sursa (job #3144158) | Cod sursa (job #2606237)
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n, x;
int currSum, maxSum, minSum;
int sp=1, fp=1;
int main() {
f>>n>>x;
currSum=maxSum=x;
if(x>=0)
minSum=0;
else
minSum=x;
for(int i=2;i<=n;i++) {
f>>x;
currSum+=x;
if(currSum-minSum>maxSum) {
maxSum=currSum-minSum;
fp=i;
}
if(minSum>currSum) {
minSum=currSum;
sp=i+1;
}
}
g<<maxSum<<' '<<sp<<' '<<fp;
f.close();
g.close();
return 0;
}