#include #include #include #include #include #include #include using namespace std; typedef long long ll; #define MAXSUM 1000000000000000000; int N, M, A, B; int current_page, current_question = 1; int res[100001]; int number_page[100001]; int mask_question[100001]; ll T[2001][2001]; void SetTab() { for (int i = 1; i < N; i++) { for (int j = i + 1; j <= N; j++) { T[i][j] = T[j][i] = llabs((i - j)*B) + llabs((number_page[i] - number_page[j])*A); } } } void solve1() { SetTab(); ll sum, tem_sum; int tem_question; for (int i = 1; i <= M; i++) { tem_sum = MAXSUM; for (int q = 1; q <= N; q++) { if (mask_question[q]) continue; if (i == 1) { sum = llabs((current_question - q) * B) + llabs((current_page - number_page[q]) * A); } else { sum = T[current_question][q]; } if (sum < tem_sum) { tem_sum = sum; tem_question = q; } } res[i] = tem_question; mask_question[tem_question]++; current_question = tem_question; current_page = number_page[tem_question]; } } void Input() { FILE *in = fopen("cheating.in", "r"); fscanf(in, "%i %i %i %i\n", &N, &M, &A, &B); for (int i = 1; i <= N; i++) { fscanf(in, "%i ", &number_page[i]); }//printf("%i\n", number_page[0]); //********* } void Output() { FILE *out = fopen("cheating.out", "w"); for (int i = 1; i <= M; i++) { fprintf(out, "%i ", res[i]); } } int main() { //timer = GetTickCount(); Input(); //if (N > 2000) return 0; solve1(); Output(); return 0; }