Pagini recente » Cod sursa (job #3151186) | Cod sursa (job #1877710) | Cod sursa (job #1093236) | Cod sursa (job #615562) | Cod sursa (job #2479715)
#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;
}