Pagini recente » Cod sursa (job #442447) | Cod sursa (job #2128642) | Cod sursa (job #875983) | Cod sursa (job #2295685) | Cod sursa (job #3330997)
#include <bits/stdc++.h>
using namespace std;
struct Intrerupator {
int camera;
int timp;
int nr;
int afecteaza[105];
};
int bec[105];
Intrerupator swt[105];
int main() {
ifstream fin("aprindere.in");
ofstream fout("aprindere.out");
int N, M;
fin >> N >> M;
for (int i = 0; i < N; i++)
fin >> bec[i];
for (int i = 0; i < M; i++) {
fin >> swt[i].camera >> swt[i].timp >> swt[i].nr;
for (int j = 0; j < swt[i].nr; j++)
fin >> swt[i].afecteaza[j];
}
int timp_total = 0;
for (int i = 0; i < M; i++) {
bool util = false;
for (int j = 0; j < swt[i].nr; j++) {
int c = swt[i].afecteaza[j];
if (bec[c] == 0) {
util = true;
break;
}
}
if (util) {
timp_total += swt[i].timp;
for (int j = 0; j < swt[i].nr; j++) {
int c = swt[i].afecteaza[j];
bec[c] = 1 - bec[c];
}
}
}
bool ok = true;
for (int i = 0; i < N; i++)
if (bec[i] == 0)
ok = false;
if (ok)
fout << timp_total;
else
fout << -1;
return 0;
}