Cod sursa(job #2394461)

Utilizator SochuKingDarabaneanu Liviu Eugen SochuKing Data 1 aprilie 2019 17:25:45
Problema Aprindere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <bits/stdc++.h>
#define NMAX 1001
#define NRI 101

using namespace std;

ifstream f ("aprindere.in");
ofstream g ("aprindere.out");

int n , m , ans;
bool a[NMAX];

struct chestie{
    int camera;
    int poz[NRI];
    int timp;
}b[NMAX];

bool cmp(chestie a , chestie b)
{
    return a.camera < b.camera;
}

int main()
{
    int i , j;
    f >> n >> m;
    for(i=0;i<n;i++)
        f >> a[i];
    for(i=1;i<=m;i++)
    {
        f >> b[i].camera >> b[i].timp >> b[i].poz[0];
        for(j=1;j<=b[i].poz[0];j++)
            f >> b[i].poz[j];
    }
    sort(b + 1 , b + m + 1 , cmp);
    for(i=1;i<=m;i++)
    {
        if(a[b[i].camera] == 0)
        {
            a[b[i].camera] = 1;
            for(j=1;j<=b[i].poz[0];j++)
                if(a[b[i].poz[j]] == 0)
                   a[b[i].poz[j]] = 1;
            else a[b[i].poz[j]] = 0;
            ans += b[i].timp;
        }
    }
    g << ans;
    return 0;
}