Cod sursa(job #1182691)

Utilizator pulseOvidiu Giorgi pulse Data 7 mai 2014 09:33:35
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>

using namespace std;

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

#define NMAX 1005

int n, m, stinse, a[NMAX], b[NMAX], cam, t, kcam, tmin;

int main ()
{
    fin >> n >> m;
    for (int i = 0; i <= n - 1; ++i)
    {
        fin >> a[i];
        if (a[i] == 0) ++stinse;
    }
    for (int i = 1; i <= m; ++i)
    {
        fin >> cam >> t >> kcam;
        for (int j = 1; j <= kcam; ++j)
            fin >> b[j];
        if (a[cam] == 0)
        {
            tmin += t;
            for (int j = 1; j <= kcam; ++j)
            {
                if (a[b[j]] == 0)
                {
                    a[b[j]] = 1;
                    --stinse;
                }
                else
                {
                    a[b[j]] = 0;
                    ++stinse;
                }
            }
        }
        if (stinse == 0) break;
    }
    fout << tmin;
    fin.close (); fout.close ();
    return 0;
}