Cod sursa(job #3330998)

Utilizator densisGeanta Denis densis Data 23 decembrie 2025 17:22:40
Problema Aprindere Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <bits/stdc++.h>
using namespace std;

struct Intrerupator {
    int camera;
    int timp;
    int nr;
    int afecteaza[105];
};

int bec[105];
Intrerupator swt[105];

int main() {
    ifstream fin("aprindere.in");
    ofstream fout("aprindere.out");

    int N, M;
    fin >> N >> M;

    for (int i = 0; i < N; i++)
        fin >> bec[i];

    for (int i = 0; i < M; i++) {
        fin >> swt[i].camera >> swt[i].timp >> swt[i].nr;
        for (int j = 0; j < swt[i].nr; j++)
            fin >> swt[i].afecteaza[j];
    }

    int timp_total = 0;

    for (int i = 0; i < M; i++) {
        bool util = false;

        for (int j = 0; j < swt[i].nr; j++) {
            int c = swt[i].afecteaza[j];
            if (bec[c] == 0) {
                util = true;
                break;
            }
        }

        if (util) {
            timp_total += swt[i].timp;

            for (int j = 0; j < swt[i].nr; j++) {
                int c = swt[i].afecteaza[j];
                bec[c] = 1 - bec[c];
            }
        }
    }

    bool ok = true;
    for (int i = 0; i < N; i++)
        if (bec[i] == 0)
            ok = false;

    if (ok)
        fout << timp_total;
    else
        fout << -1;

    return 0;
}