Cod sursa(job #2920824)

Utilizator victor_gabrielVictor Tene victor_gabriel Data 26 august 2022 10:24:47
Problema Aprindere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#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]) {
            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;
}