Pagini recente » Cod sursa (job #734249) | Cod sursa (job #1815786) | Cod sursa (job #1601536) | Cod sursa (job #734223) | Cod sursa (job #1070521)
#include <cstdio>
#define MAX_N 1000
#define MAX_LIGHTS 100
int stage[MAX_N], time[MAX_N], nr_rooms[MAX_N];
int light[MAX_N][MAX_LIGHTS];
void read( FILE *fin, int &n ) {
int m;
fscanf( fin, "%d%d", &n, &m );
for ( int i = 0; i < n; ++i )
fscanf( fin, "%d", &stage[i] );
while ( m ) {
int room;
fscanf( fin, "%d", &room );
fscanf( fin, "%d", &time[room] );
fscanf( fin, "%d", &nr_rooms[room] );
for ( int j = 0; j < nr_rooms[room]; ++j )
fscanf( fin, "%d", &light[room][j] );
--m;
}
}
void action( int room ) {
for ( int j = 0; j < nr_rooms[room]; ++j ) {
++stage[light[room][j]];
stage[light[room][j]] &= 1;
}
}
int solve( int n ) {
int ans = 0;
for ( int i = 0; i < n; ++i )
if ( !stage[i] ) {
ans += time[i];
action( i );
}
return ans;
}
int main() {
FILE *fin, *fout;
fin = fopen( "aprindere.in", "r" );
int n;
read( fin, n );
fclose( fin );
fout = fopen( "aprindere.out", "w" );
fprintf( fout, "%d\n", solve( n ) );
fclose( fout );
}