Cod sursa(job #2910716)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 24 iunie 2022 17:34:24
Problema Buline Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>

using namespace std;

ifstream cin ("buline.in");
ofstream cout ("buline.out");

const int N = 2e5;
int a[N + 1];

int n, x, y;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x >> y;
        if (!y)
            x = -x;
        a[i] = a[i + n] = x;
    }
    int s = -1, smax = -1, st, dr, st1;
    for (int i = 1; i < 2 * n; ++i)
    {
        if (dr - st == n - 1)
        {
            if (s > smax)
            {
                smax = s;
                st = st1;
                dr = i;
            }
            s = 0;
        }
        if (s + a[i] < a[i])
            s = a[i], st1 = i;
        else
            s += a[i];
        if (s > smax)
        {
            smax = s;
            st = st1;
            dr = i;
        }
    }
    cout << smax << ' ' << st << ' ' << dr - st + 1 << '\n';
    return 0;
}