56332023-08-29 13:33:30TomaSajtLegtöbbször szomszédok (75 pont)cpp17Accepted 75/7514ms5384 KiB
#include <bits/stdc++.h>
using namespace std;

ostream& operator<<(ostream& s, const pair<int, int>& p) {
  return s << p.first << ' ' << p.second;
}

pair<int, int> get_res(map<int, int>& cnt_map) {
  return *max_element(cnt_map.begin(), cnt_map.end(), [](auto& p1, auto& p2) { return p1.second < p2.second; });
}

int main() {
  cin.tie(0), ios::sync_with_stdio(0);

  int n, m;
  cin >> n >> m;

  int max_less_ind = -1, min_more_ind = -1;
  map<int, int> max_less_ind_cnt, min_more_ind_cnt;

  vector<int> scores(n + 1);
  for (int i = 1; i <= n; i++) cin >> scores[i];
  bool track = 0;
  for (int i = 1; i <= n; i++) {
    if (i == m) track = 1;

    if (scores[i] > scores[m] && (min_more_ind == -1 || scores[i] < scores[min_more_ind])) min_more_ind = i;
    if (scores[i] < scores[m] && (max_less_ind == -1 || scores[i] > scores[max_less_ind])) max_less_ind = i;

    if (!track) continue;
    if (max_less_ind != -1) max_less_ind_cnt[max_less_ind]++;
    if (min_more_ind != -1) min_more_ind_cnt[min_more_ind]++;
  }

  if (min_more_ind == -1)
    cout << -1 << '\n';
  else
    cout << get_res(min_more_ind_cnt) << '\n';

  if (max_less_ind == -1)
    cout << -1;
  else
    cout << get_res(max_less_ind_cnt);
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1704 KiB
2Accepted0/013ms2564 KiB
3Accepted2/22ms2072 KiB
4Accepted2/23ms2312 KiB
5Accepted4/43ms2664 KiB
6Accepted4/43ms2768 KiB
7Accepted3/33ms2928 KiB
8Accepted4/43ms2952 KiB
9Accepted4/43ms3312 KiB
10Accepted4/44ms3536 KiB
11Accepted4/43ms3496 KiB
12Accepted4/44ms3528 KiB
13Accepted4/44ms3652 KiB
14Accepted4/44ms3764 KiB
15Accepted4/44ms3708 KiB
16Accepted4/46ms4036 KiB
17Accepted4/47ms4044 KiB
18Accepted4/48ms4348 KiB
19Accepted4/414ms4820 KiB
20Accepted4/414ms5032 KiB
21Accepted4/414ms5104 KiB
22Accepted4/414ms5384 KiB