Cod sursa(job #2656807)

Utilizator VNohaiNohai Vlad-Auras VNohai Data 8 octombrie 2020 19:17:44
Problema Aprindere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

ifstream fin("aprindere.in");
ofstream fout("aprindere.out");

int costuri[1001], af=0, cost;

int main()
{
    bool v[1001];
    vector <int> buton[1001];
    int n, m, poz, k;
    fin>>n>>m;
    for(int i=0; i<n; i++)
    {
    int val;
    fin>>val;
    if(val==0) v[i]=false;
    else v[i]=true;
    }
    for(int i=1; i<=m; i++)
    {
    fin>>poz>>cost>>k;
    costuri[poz]=cost;
    for(int j=1; j<=k; j++)
    {
    int a;
    fin>>a;
    buton[poz].push_back(a);
    }
    }
    for(int i=0; i<n; i++)
    {
    if(v[i]==false)
    {
    af=af+costuri[i];
    for(int j=0; j<buton[i].size(); j++)
    v[buton[i][j]]=!v[buton[i][j]];
    }
    }
    fout<<af;
    return 0;
}