Cod sursa(job #2498299)

Utilizator PopeangaMihneaPopeanga Mihnea- Stefan PopeangaMihnea Data 23 noiembrie 2019 18:41:57
Problema Aprindere Scor 100
Compilator cpp-64 Status done
Runda ad_hoc Marime 0.86 kb
#include <bits/stdc++.h>

using namespace std;

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

struct usu
{
    int c, t, nr;
    int a[101];

    bool operator <(const usu &aux)const
    {
        return (c < aux.c) || (c == aux.c && t < aux.t);
    }
}x[1001];

int n, m;
int ok[1001];

int main()
{
    fin >> n >> m;

    for(int i = 0; i < n; ++i) fin >> ok[i];

    for(int i = 1; i <= m; ++i)
    {
        fin >> x[i].c >> x[i].t >> x[i].nr;
        for(int j = 1; j <= x[i].nr; ++j) fin >> x[i].a[j];
    }

    sort(x + 1, x + m + 1);

    int sol = 0;

    for(int i = 1; i <= m; ++i)
    {
        if(!ok[x[i].c])
        {
            sol = sol + x[i].t;
            for(int j = 1; j <= x[i].nr; ++j) ok[x[i].a[j]] = (ok[x[i].a[j]] + 1) % 2;
        }
    }

    fout << sol << "\n";
    return 0;
}