Cod sursa(job #3338543)

Utilizator gabrielrusu2712Rusu Gabriel Eduard gabrielrusu2712 Data 3 februarie 2026 20:39:10
Problema Buline Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream fin("buline.in");
ofstream fout("buline.out");
vector<int> cerc;
int n;

bool terminatDeCitit = false;

int getX(int& it) {
    int x;
    if (it == n) {
        it = 0;
    } else if (it == cerc.end() - cerc.begin()) {
        fin >> x;
        int sign;
        fin >> sign;
        sign = sign ? 1 : -1;
        x *= sign;
        cerc.push_back(x);
    }
    if (it < cerc.end() - cerc.begin()) {
        x = cerc.at(it);
    }
    return x;
}

int afisare(int smax, int p, int u) {
    p++; //+1 deoarece impl. fol. index. de la 0
    u++;
    int l = p < u ? u - p + 1 : n - p + u + 1;
    fout << smax << " " << p <<  " " << l;
}

int main() {
    fin >> n;
    int s = 0;
    int smax = -100000;
    int p = 0;
    int u = 0;
    int pc = 0;
    int it = 0;
    int nrIncrementari = 1;
    while (nrIncrementari < 2 * n) {
        int x = getX(it);
        if (s < 0) {
            s = 0;
            pc = it;
        }
        s += x;
        if (smax < s) {
            smax = s;
            u = it;
            p = pc;
        }
        nrIncrementari++;
        it++;
    }
    afisare(smax, p, u);
    return 0;
}