Cod sursa(job #2393870)

Utilizator SochuKingDarabaneanu Liviu Eugen SochuKing Data 1 aprilie 2019 10:04:16
Problema Aprindere Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 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;
int 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=1;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[i];
    }
    sort(b + 1 , b + m + 1 , cmp);
    for(i=1;i<=m;i++)
    {
        if(a[b[i].camera] == 0)
        {
            for(j=1;j<=b[i].poz[0];j++)
                if(a[b[i].poz[i]] == 0)
                   a[b[i].poz[i]] = 1 , ans += b[i].timp;
            else a[b[i].poz[i]] = 0 , ans += b[i].timp;
        }
    }
    g << ans;
    return 0;
}