Cod sursa(job #2870637)

Utilizator AswVwsACamburu Luca AswVwsA Data 12 martie 2022 14:38:58
Problema Buline Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <fstream>
#include <climits>
using namespace std;
const int NMAX = 200003;
int v[NMAX];
int main()
{
    ifstream cin("buline.in");
    ofstream cout("buline.out");
    int n, i;
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        int c;
        cin >> v[i] >> c;
        if (c == 0)
            v[i] *= -1;
        //cout << v[i] << " ";
    }
    //cout << "\n";
    int smax = INT_MIN, smin = INT_MAX, stmin, drmin, stmax, drmax;
    int st1, st2;
    int s = 0, s1 = 0, s2 = 0;
    for (i = 1; i <= n; i++)
    {
        s += v[i];
        if (s1 + v[i] < v[i])
        {
            s1 = 0;
            st1 = i;
        }
        if (s2 + v[i] > v[i])
        {
            s2 = 0;
            st2 = i;
        }
        s1 += v[i];
        s2 += v[i];
        if (s1 > smax)
        {
            smax = s1;
            stmax = st1;
            drmax = i;
        }
        if (s2 < smin)
        {
            smin = s2;
            stmin = st2;
            drmin = i;
        }
    }
    s -= smin;
    /*cout << stmax << " " << drmax << "\n";
    cout << stmin << " " << drmin << "\n";
    return 0;*/
    if (s == 0)
        cout << smax << " " << stmax << ' ' << drmax - stmax + 1;
    else if (smax > s)
        cout << smax << " " << stmax << " " << drmax - stmax + 1;
    else
    {
        cout << s << " " << drmin + 1 << " " << n - (drmin - stmin + 1);
    }
}