Pagini recente » Cod sursa (job #3001339) | Cod sursa (job #3179456) | Cod sursa (job #3214694) | Cod sursa (job #1000657) | Cod sursa (job #2490813)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("aprindere.in");
ofstream fout("aprindere.out");
const int MAXN = 1010;
struct Switch {
int id, time;
bool exists;
vector<int> rooms;
};
int N, M;
Switch arr[MAXN];
bool isOn[MAXN];
int main() {
fin >> N >> M;
for (int i = 0; i < N; i++) {
int x;
fin >> x;
isOn[i] = ( x == 1);
}
for (int i = 0; i < M; i++) {
Switch tmp;
tmp.exists = true;
fin >> tmp.id >> tmp.time;
int sz;
fin >> sz;
//cout << tmp.id << " " << tmp.time << " " << sz<< endl;
for (int room; sz--;) {
fin >> room;
tmp.rooms.push_back(room);
}
arr[tmp.id] = tmp;
}
int ans = 0;
for (int i = 0 ; i < N; i++) {
if (!isOn[i]) {
//cout << i << " " << arr[i].exists << endl;
// cout << i << endl;
// for (int i = 0; i < N; i++) cout << isOn[i] << " " ;
// cout << endl;
if (arr[i].exists) {
ans += arr[i].time;
for (auto it: arr[i].rooms) isOn[it] = !isOn[it];
} else {
// no solution
cout << "no solution";
}
// cout << i << endl;
// for (int i = 0; i < N; i++) cout << isOn[i] << " " ;
// cout << endl;
}
}
fout << ans;
return 0;
}