Pagini recente » Cod sursa (job #2660126) | Cod sursa (job #3279126) | Cod sursa (job #3152454) | Cod sursa (job #1847489) | Cod sursa (job #2920823)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("aprindere.in");
ofstream fout("aprindere.out");
const int DIM = 1001;
struct switchInfo{
int roomNo, time, roomNumber;
int rooms[DIM];
} lightSwitch[DIM];
int n, m;
bool light[DIM];
bool comp(switchInfo a, switchInfo b) {
return a.roomNo < b.roomNo;
}
int main() {
fin >> n >> m;
for (int i = 0; i < n; i++)
fin >> light[i];
for (int i = 1; i <= m; i++) {
fin >> lightSwitch[i].roomNo >> lightSwitch[i].time >> lightSwitch[i].roomNumber;
for (int j = 1; j <= lightSwitch[i].roomNumber; j++)
fin >> lightSwitch[i].rooms[j];
}
sort(lightSwitch + 1, lightSwitch + m + 1, comp);
int totalTime = 0;
for (int i = 1; i <= m; i++) {
if (!light[lightSwitch[i].roomNo]) {
int count = 0;
for (int j = 1; j <= lightSwitch[i].roomNumber; j++)
if (!light[lightSwitch[i].rooms[j]])
count++;
if (count >= lightSwitch[i].roomNumber - count) {
totalTime += lightSwitch[i].time;
for (int j = 1; j <= lightSwitch[i].roomNumber; j++)
light[lightSwitch[i].rooms[j]] = !light[lightSwitch[i].rooms[j]];
}
}
}
fout << totalTime;
return 0;
}