Pagini recente » Cod sursa (job #1060159) | Cod sursa (job #1995510) | Cod sursa (job #66374) | Cod sursa (job #340582) | Cod sursa (job #2930612)
#include <bits/stdc++.h>
using namespace std;
#define vecLen 200001
ifstream fin("buline.in");
ofstream fout("buline.out");
int vec[vecLen];
int main()
{
cin.rdbuf(fin.rdbuf());
cout.rdbuf(fout.rdbuf());
int n, x, sign;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x;
cin >> sign;
vec[i] = x;
if (!sign)
vec[i] *= -1;
}
tuple<int, int, int> cMax{0, 0, 0}, tMax{-1, 0, 0};
bool wrapped = false;
for (int i = 0; i < 2 * n; i++)
{
if (vec[i % n] > vec[i % n] + get<2>(cMax))
get<0>(cMax) = i % n, get<1>(cMax) = 1, get<2>(cMax) = vec[i % n];
else
get<1>(cMax) += 1, get<2>(cMax) += vec[i % n];
if (get<1>(cMax) > n)
break;
if (get<2>(cMax) > get<2>(tMax))
tMax = cMax;
}
cout << get<2>(tMax) << " " << get<0>(tMax) + 1 << " " << get<1>(tMax);
return 0;
}