Pagini recente » Cod sursa (job #2377019) | Cod sursa (job #926535) | Cod sursa (job #1782915) | Cod sursa (job #2538901) | Cod sursa (job #3338543)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("buline.in");
ofstream fout("buline.out");
vector<int> cerc;
int n;
bool terminatDeCitit = false;
int getX(int& it) {
int x;
if (it == n) {
it = 0;
} else if (it == cerc.end() - cerc.begin()) {
fin >> x;
int sign;
fin >> sign;
sign = sign ? 1 : -1;
x *= sign;
cerc.push_back(x);
}
if (it < cerc.end() - cerc.begin()) {
x = cerc.at(it);
}
return x;
}
int afisare(int smax, int p, int u) {
p++; //+1 deoarece impl. fol. index. de la 0
u++;
int l = p < u ? u - p + 1 : n - p + u + 1;
fout << smax << " " << p << " " << l;
}
int main() {
fin >> n;
int s = 0;
int smax = -100000;
int p = 0;
int u = 0;
int pc = 0;
int it = 0;
int nrIncrementari = 1;
while (nrIncrementari < 2 * n) {
int x = getX(it);
if (s < 0) {
s = 0;
pc = it;
}
s += x;
if (smax < s) {
smax = s;
u = it;
p = pc;
}
nrIncrementari++;
it++;
}
afisare(smax, p, u);
return 0;
}