Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("Ofast")
- #include <iostream>
- #include <stdio.h>
- #include <vector>
- #include <set>
- #include <unordered_set>
- #include <map>
- #include <unordered_map>
- #include <deque>
- #include <algorithm>
- #include <math.h>
- #include <random>
- #define ff first
- #define ss second
- #define pb push_back
- #define mp make_pair
- #define int long long
- #define double long double
- #define Matrix vector<vector<int> >
- #define kektor vector
- #define pii pair<int, int>
- #define all(x) x.begin(), x.end()
- using namespace std;
- typedef long long ll;
- int RandInt(int min, int max) {
- if (max < min) {
- swap(min, max);
- }
- random_device rd;
- mt19937 mt(rd());
- uniform_int_distribution<int> dist(min, max);
- return dist(mt);
- }
- const int maxn = 3e5 + 1, mod = 1e9 + 7;
- bool debug = false;
- int n, k;
- pii cnt[maxn];
- vector<int> ans(int el1) {
- set<pii> dd1;
- set<pii> dd2;
- set<pii> dd3;
- vector<int> ans;
- for (int i = 0; i < n; ++i) {
- if (cnt[i].ff < el1) {
- dd1.insert({cnt[i].ff, cnt[i].ss});
- } else if (cnt[i].ff == el1) {
- dd2.insert({cnt[i].ff, cnt[i].ss});
- } else {
- dd3.insert({cnt[i].ff, cnt[i].ss});
- }
- }
- int left1 = dd1.size();
- int mid = dd2.size() - 1;
- int right1 = dd3.size();
- int kk = min(left1, right1);
- left1 -= kk;
- right1 -= kk;
- if (right1 != 0) {
- int tt = min(mid, right1);
- right1 -= tt;
- } else {
- int tt = min(mid, left1);
- left1 -= tt;
- }
- int siz1 = dd1.size() - left1;
- int siz2 = dd3.size() - right1;
- for (int i = 0; i < siz1; ++i) {
- ans.pb((*(dd1.begin())).ss + 1);
- dd1.erase(dd1.begin());
- }
- for (int i = 0; i < siz2; ++i) {
- ans.pb((*dd3.begin()).ss + 1);
- dd3.erase(dd3.begin());
- }
- for (auto i : dd2) {
- ans.pb(i.ss + 1);
- }
- return ans;
- }
- void solve() {
- cin >> n >> k;
- for (int i = 0; i < n; ++i) {
- cin >> cnt[i].ff;
- cnt[i].ss = i;
- }
- sort(cnt, cnt + n);
- int el1 = -1;
- int el2 = -1;
- for (int i = 0; i < n; ++i) {
- if (cnt[i].ff >= k) {
- el2 = cnt[i].ff;
- break;
- } else {
- el1 = cnt[i].ff;
- }
- }
- vector<int> ans1, ans2;
- if (el1 != -1) {
- ans1 = ans(el1);
- }
- if (el2 != -1) {
- ans2 = ans(el2);
- }
- if (el1 == -1) {
- cout << ans2.size() << '\n';
- for (auto i : ans2) {
- cout << i << " ";
- }
- return;
- } else if (el2 == -1) {
- cout << ans1.size() << '\n';
- for (auto i : ans1) {
- cout << i << " ";
- }
- return;
- } else if (abs(k - el1) < abs(k - el2)) {
- cout << ans1.size() << '\n';
- for (auto i : ans1) {
- cout << i << " ";
- }
- return;
- } else if (abs(k - el1) > abs(k - el2)) {
- cout << ans2.size() << '\n';
- for (auto i : ans2) {
- cout << i << " ";
- }
- return;
- } else if (ans1.size() > ans2.size()) {
- cout << ans1.size() << '\n';
- for (auto i : ans1) {
- cout << i << " ";
- }
- return;
- } else {
- cout << ans2.size() << '\n';
- for (auto i : ans2) {
- cout << i << " ";
- }
- return;
- }
- }
- signed main() {
- /*!
- !*/
- cout.precision(10);
- cout << fixed;
- if (!debug) {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- }
- //freopen("TASK.in", "r", stdin);
- //freopen("TASK.out", "w", stdout);
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement