Cod sursa(job #2479715)

Utilizator Radu_FilipescuFilipescu Radu Radu_Filipescu Data 24 octombrie 2019 13:00:23
Problema Aprindere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <fstream>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;

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

const int NMAX = 1030;

int N, M;
bool stare[NMAX];
struct intre
{
    vector <int> pos;
    int cost;

    bool operator < ( const intre & A ) const
    {
        return pos[0] < A.pos[0];
    }
};
vector <intre> V;

int main()
{
    fin >> N >> M;
    for( int i = 0; i < N; ++i )
        fin >> stare[i];

    for( int i = 1; i <= M; ++i )
    {
        int p, T, nr_p;
        intre aux;
        vector <int> aux2;

        fin >> p >> T >> nr_p;

        aux.cost = T;
        for( int j = 1; j <= nr_p; ++j )
        {
            int aux;
            fin >> aux;
            aux2.push_back( aux );
        }

        sort( aux2.begin(), aux2.end() );

        aux.pos = aux2;
        V.push_back( aux );
    }

    sort( V.begin(), V.end() );

    int cost = 0;
    for( int i = 0; i < V.size(); ++i )
       if( stare[ V[i].pos[0] ] == 0 )
       {
          for( int j = 0; j < V[i].pos.size(); ++j )
            stare[ V[i].pos[j] ] = 1 - stare[ V[i].pos[j] ];

          cost += V[i].cost;

          //fout << V[i].pos[0] << ' ';
       }

    fout << cost;

    fin.close();
    fout.close();

    return 0;
}