Cod sursa(job #1820287)

Utilizator DM1234Radu Radu DM1234 Data 1 decembrie 2016 15:28:24
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin("aprindere.in");
ofstream fout("aprindere.out");
int c[1005][1005],a[1005],t[1005],l[1005],n,m,s;

void citire()
{
	int i,j,k;
	fin>>n;
	fin>>m;
	for(i=0; i<n; i++)
		fin>>a[i];
	for(i=1; i<=m; i++)
	{
		fin>>j;
		fin>>t[j];
		fin>>l[j];
		for(k=1; k<=l[j]; k++)
			fin>>c[j][k];
	}
}

void greedy()
{
	int i,j;
	for(i=0; i<n; i++)
	{
		if(a[i]==0)
		{
			s+=t[i];
			for(j=1; j<=l[i]; j++)
			{
				a[c[i][j]]=!a[c[i][j]];
			}
		}
	}
}

int main()
{
	citire();
	greedy();
	fout<<s<<"\n";
}