Pagini recente » Cod sursa (job #1802402) | Cod sursa (job #3198962) | Cod sursa (job #56871) | Cod sursa (job #2656973) | Cod sursa (job #998453)
Cod sursa(job #998453)
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iterator>
using namespace std;
const string file = "ssm";
const string infile = file + ".in";
const string outfile = file + ".out";
const int INF = 0x3f3f3f3f;
int N;
int maxSum;
int maxStart;
int maxEnd;
int main()
{
fstream fin(infile.c_str(), ios::in);
fin >> N;
int c;
fin >> c;
int cSum = c;
int cStart = 0;
int cEnd = 0;
maxSum = c;
maxStart = 0;
maxEnd = 0;
for(int i = 1; i < N; i++)
{
int c;
fin >> c;
if(c + cSum > c)
{
cSum = c + cSum;
cEnd++;
}
else
{
cSum = c;
cStart = i;
cEnd = i;
}
if(cSum > maxSum)
{
maxSum = cSum;
maxStart = cStart;
maxEnd = cEnd;
}
}
fin.close();
fstream fout(outfile.c_str(), ios::out);
fout << maxSum << " " << maxStart + 1 << " " << maxEnd + 1<< "\n";
fout.close();
}