#include #include #include #include using namespace std; int N, M, A, B; vector p; vector sp1, sp2; long long score(const vector& sp, int& start) { int64_t total = (int64_t)A * p[sp[0]] + B * sp[0]; for (int i = 1; i < M; i++) total += (int64_t)A * std::abs(p[sp[i]] - p[sp[i - 1]]) + B * std::abs(sp[i] - sp[i - 1]); int64_t min_total = total; start = 0; for (int i = 0, c = sp.size() - M; i < c; i++) { total -= (int64_t)A * p[sp[i]] + B * sp[i] + (int64_t)A * std::abs(p[sp[i]] - p[sp[i + 1]]) + B * std::abs(sp[i] - sp[i + 1]); total += (int64_t)A * p[sp[i + 1]] + B * sp[i + 1] + (int64_t)A * std::abs(p[sp[M + i - 1]] - p[sp[M + i]]) + B * std::abs(sp[M + i - 1] - sp[M + i]); if (total < min_total) { min_total = total; start = i + 1; } } return min_total; } void store(const char oname[], const vector& sp, int start) { ofstream fout(oname); for (int i = 0; i < M; i++) fout << sp[start + i] + 1 << " "; } int solve(const char iname[], const char oname[]) { ifstream fin(iname); fin >> N >> M >> A >> B; p.resize(N); sp1.resize(N); for (int i = 0; i < N; i++) { fin >> p[i]; sp1[i] = i; } sp2 = sp1; int s1 = 0; int64_t t1 = score(sp1, s1); sort(sp2.begin(), sp2.end(), [](int l, int r)-> bool { return p[l] < p[r]; }); int s2 = 0; int64_t t2 = score(sp2, s2); if (t1 < t2) store(oname, sp1, s1); else store(oname, sp2, s2); return 0; } int main() { return solve("cheating.in", "cheating.out"); }