Pagini recente » Cod sursa (job #867857) | Cod sursa (job #576656) | Cod sursa (job #367918) | Cod sursa (job #196751) | Cod sursa (job #672048)
Cod sursa(job #672048)
// http://infoarena.ro/problema/ssm
#include <fstream>
using namespace std;
const int oo = 0x3f3f3f3f;
ifstream in("ssm.in");
ofstream out("ssm.out");
int length,bestSum=-oo,sum=-oo,number,Left,Right,tmpLeft,position;
int main() {
in >> length;
for(position=1;position<=length;position++) {
in >> number;
if(sum < 0) {
tmpLeft = position;
sum = number;
}
else
sum += number;
if(bestSum < sum) {
bestSum = sum;
Left = tmpLeft;
Right = position;
}
}
out << bestSum << " " << Left << " " << Right << "\n";
in.close();
out.close();
return (0);
}