Pagini recente » Cod sursa (job #2762112) | Cod sursa (job #2974999) | Cod sursa (job #1006200) | Cod sursa (job #2882696) | Cod sursa (job #503688)
Cod sursa(job #503688)
#include <fstream>
using namespace std;
ifstream in ("buline.in");
ofstream out ("buline.out");
const int N = 1 << 19;
int n, v[N], sumatut;
void citire () {
in >> n;
for (int i = 1, x; i <= n; ++i) {
in >> v[i] >> x;
v[i] = !x ? -v[i] : v[i];
v[n + i] = v[i];
sumatut += v[i];
}
}
void exe () {
int sc = v[1], smax = v[1], lc = 1, inceput = 1, p = 1, l = 1;
for (int i = 2; i <= (n << 1); ++i) {
if (sc < 0) {
sc = v[i];
inceput = i;
lc = 1;
} else {
sc += v[i];
++lc;
}
if (lc == n) {
break;
}
if (sc > smax) {
smax = sc;
l = lc;
p = inceput;
}
}
if (l < n) {
out << smax << ' ' << p << ' ' << l;
} else {
out << sumatut << " 1 " << n << "\n";
}
}
int main () {
citire ();
exe ();
return 0;
}