Cod sursa(job #2910717)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 24 iunie 2022 17:50:31
Problema Buline Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
///mai bine cu smin, smax:)

#include <fstream>
#include <climits>

using namespace std;

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

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

int n, x, y;

int main()
{
    cin >> n;
    int s = 0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x >> y;
        if (!y)
            x = -x;
        a[i] = x;
        s += x;
    }
    int smx = -INF, smax = -INF, stmx, drmx, st1mx;
    for (int i = 1; i <= n; ++i)
    {
        if (smx + a[i] < a[i])
            smx = a[i], st1mx = i;
        else
            smx += a[i];
        if (smx > smax)
        {
            smax = smx;
            stmx = st1mx;
            drmx = i;
        }
    }
    int smn = INF, smin = INF, stmn, drmn, st1mn;
    for (int i = 1; i <= n; ++i)
    {
        if (1ll * (smn + a[i]) > a[i])
            smn = a[i], st1mn = i;
        else
            smn += a[i];
        if (smn < smin)
        {
            smin = smn;
            stmn = st1mn;
            drmn = i;
        }
    }
    //cout << smax << ' ' << smin << ' ' << s << '\n';
    s -= smin;
    if (smax > s)
        cout << smax << ' ' << stmx << ' ' << drmx - stmx + 1 << '\n';
    else
        cout << s << ' ' << drmn + 1  << ' ' << n - (drmn - stmn + 1) << '\n';
    return 0;
}