Cod sursa(job #535743)

Utilizator Catah15Catalin Haidau Catah15 Data 17 februarie 2011 18:34:51
Problema Aprindere Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#define MAXN 1002
#define NRMAX 103
using namespace std;

bool x[MAXN];

struct intrerupator
{
	int timp, nr, mod[NRMAX];
}a[MAXN];

int main()
{
	int n, m;
	
	ifstream f("aprindere.in");
	ofstream g("aprindere.out");
	
	f >> n >> m;
	
	for(int i = 0; i < n; ++i)
		f >> x[i];
	
	for(int i = 1; i <= m; ++i)
	{
		int cam;
		
		f >> cam;
		
		f >> a[cam].timp >> a[cam].nr;
		
		for(int j = 1; j <= a[cam].nr; ++j)
			f >> a[cam].mod[j];
	}
	
	int T = 0;
	
	for(int i = 0; i < n; ++i)
	{
		if(!x[i])
		{
			T += a[i].timp;
			
			for(int j = 1; j <= a[i].nr; ++j)
				if(x[a[i].mod[j]])
					x[a[i].mod[j]] = 0;
				else
					x[a[i].mod[j]] = 1;
		}
	}
	
	g << T;
	
	f.close();
	g.close();
	
	return 0;
}