Cod sursa(job #3275588)

Utilizator CimpoesuFabianCimpoesu Fabian George CimpoesuFabian Data 10 februarie 2025 21:55:07
Problema Aprindere Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("aprindere.in");
ofstream fout("aprindere.out");

/**
*/

int n, m, c, nrc, t, fr[1001];

struct val
{
    int timp, nr, cam[1001];
}b[1001];

bool Comp(val a, val b)
{
    return a.timp < b.timp;
}

int main()
{
    int i, j, x, Ttotal = 0, cnt;
    fin >> n >> m;
    for (i = 0 ; i < n ; i++)
    {
        fin >> x;
        if (x == 1)
            ++fr[i];
    }
    for (i = 1 ; i <= m ; i++)
    {
        fin >> c >> t >> nrc;
        Ttotal += t;
        b[c].timp = t; b[c].nr = nrc;
        for (j = 1 ; j <= nrc ; j++)
        {
            fin >> x;
            ++fr[x];
            b[c].cam[j] = x;
        }
    }
    sort (b, b + n, Comp);
    for (i = 0 ; i < n ; i++)
    {
        cnt = 0;
        for (j = 1 ; j <= b[i].nr ; j++)
            if (fr[b[i].cam[j]] % 2 == 0)
                ++cnt;
        if (cnt == b[i].nr)
        {
            Ttotal -= b[i].timp;
            for (j = 1 ; j <= b[i].nr ; j++)
                --fr[b[i].cam[j]];
        }
    }
    fout << Ttotal;
    return 0;
}