Cod sursa(job #2965099)

Utilizator Cezar2009Cezar Mihai Titihazan Cezar2009 Data 14 ianuarie 2023 14:15:46
Problema Aprindere Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.39 kb
//https://infoarena.ro/problema/aprindere
#include <bits/stdc++.h>
using namespace std;

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

#pragma pack(1)
struct camera
{
    short int c;
    short int t;
    int nr;
    int nrc[1010];
}c[1010];
bool comparare(struct camera a,struct camera b)
{
    if(a.c<b.c)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int main()
{
    int i,j,n,m,tt=0,b;
    bitset <1010> bit;
    fin>>n>>m;
    for(i=0;i<n;i++)
    {
       fin>>b;
       bit[i]=b;
    }
    for(i=0;i<m;i++)
    {
        fin>>c[i].c>>c[i].t>>c[i].nr;
        for(j=0;j<c[i].nr;j++)
        {
            fin>>c[i].nrc[j];
        }
    }
    sort(c+1,c+1+m,comparare);
    for(i=0;i<n;i++)
    {
        //cout<<i<<" ";
        if(bit[i]==0&&c[i].nr!=0)
        {
            tt=tt+c[i].t;
           // cout<<i<<" "<<c[i].t<<" ";
            for(j=0;j<c[i].nr;j++)
            {
                //cout<<bit[c[i].nrc[j]]<<" ";
                if(bit[c[i].nrc[j]]==1)
                {
                    bit[c[i].nrc[j]]=0;
                }
                else if(bit[c[i].nrc[j]]==0)
                {
                    bit[c[i].nrc[j]]=1;
                }
                //cout<<bit[c[i].nrc[j]]<<"   ";
            }
           // cout<<"\n";
        }
    }
    fout<<tt;
	return 0;
}