Cod sursa(job #2398966)

Utilizator AndreibatmanAndrei Croitoriu Andreibatman Data 6 aprilie 2019 16:13:53
Problema Aprindere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("aprindere.in");
ofstream fout("aprindere.out");
struct chestie{
    int c;
    int p[110];
    int t;
}b[1010];
int n,m,nr,i,j;
bool v[1010];
bool cmp(chestie a , chestie b)
{
    return a.c < b.c;
}
int main()
{
    fin>>n>>m;
    for(i=0;i<n;i++)
        fin>>v[i];
    for(i=1;i<=m;i++)
    {
        fin>>b[i].c>>b[i].t>>b[i].p[0];
        for(j=1;j<=b[i].p[0];j++)
            fin>>b[i].p[j];
    }
    sort(b+1,b+m+1,cmp);
    for(i=1;i<=m;i++)
        if(v[b[i].c]==0)
        {
            v[b[i].c]=1;
            for(j=1;j<=b[i].p[0];j++)
                   v[b[i].p[j]]=1-v[b[i].p[j]];
            nr=nr+b[i].t;
        }
    fout<<nr;
    return 0;
}