#define _CRT_SECURE_NO_WARNINGS //#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int N, M; clock_t t; struct actors_in_scenes { int scenes[5001]; } ais[10001]; struct scenes{ int opening_scene; int br; bool operator < (scenes &vv) { return (this->br > vv.br); } } sc[5001]; int full_scenes[5001]; int price[10001]; ll full_sum, tem_full_sum; int result[5001], final_result[5001]; int Downtime(int actor) { int min_scene = M, max_scene = 1; for (int i = 1; i <= ais[actor].scenes[0]; i++) { if (result[ais[actor].scenes[i]] < min_scene) min_scene = result[ais[actor].scenes[i]]; if (result[ais[actor].scenes[i]] > max_scene) max_scene = result[ais[actor].scenes[i]]; } return max_scene - min_scene + 1; } void FullPrice() { tem_full_sum = 0; for (int i = 1; i <= N; i++) { tem_full_sum += Downtime(i) * price[i]; } } void SaveFinalResult() { for (int i = 1; i <= M; i++) final_result[result[i]] = i; } void Solve() { int a; FullPrice(); full_sum = tem_full_sum; for (int i = 1; i < M; i++) { if (clock() - t > 4.8 * CLOCKS_PER_SEC) return; a = result[i]; result[i] = result[i + 1]; result[i + 1] = a; for (int k = 1; k <= M; k++) ; FullPrice(); if (tem_full_sum < full_sum) { full_sum = tem_full_sum; continue; } result[i + 1] = result[i]; result[i] = a; } } void SwapScenes(int at, int bt) { int a = result[at]; result[at] = result[bt]; result[bt] = a; } void Solve1() { int tem = 0; int a = M / 2; int b = a + 1; int at = a, bt = b; sort(&sc[1], &sc[M + 1]); //for (int i = 1; i <= M; i++) { printf("br = %i\n", sc[i].br); } //************* //for (int i = 1; i <= M; i++) { printf("opening_scene = %i\n", sc[i].opening_scene); }//***** for (int i = 1; i <= M; i++) { if (tem == 0) { result[a] = sc[i].opening_scene; a--; tem = 1; continue; } result[b] = sc[i].opening_scene; b++; tem = 0; } //a = result[M / 2]; result[M / 2] = result[M / 2 + 1]; result[M / 2 + 1] = a; // new **** //SwapScenes(at, bt); } void Input() { int act, v; FILE *in = fopen("star.in", "r"); fscanf(in, "%i %i\n", &N, &M); for (int i = 1; i <= M; i++) result[i] = i; for (int i = 1; i <= N; i++) { fscanf(in, "%i ", &price[i]); } for (int i = 1; i <= M; i++) { sc[i].opening_scene = i; // new ************ fscanf(in, "%i ", &act); sc[i].br = act; // new ************ for (int j = 1; j <= act; j++) { fscanf(in, "%i ", &v); ais[v].scenes[0]++; ais[v].scenes[ais[v].scenes[0]] = result[i]; } } } /*void Output() { SaveFinalResult(); FILE *out = fopen("star.out", "w"); for (int i = 1; i <= M; i++) { fprintf(out, "%i ", final_result[i]); } } */ void Output1() { FILE *out = fopen("star.out", "w"); for (int i = 1; i <= M; i++) { fprintf(out, "%i ", result[i]); } } int main() { t = clock(); Input(); //Solve(); Solve1(); //Output(); //FullPrice(); full_sum = tem_full_sum; //printf("tem_full_sum = %i\n", tem_full_sum); Output1(); return 0; }