56322023-08-29 13:21:31TomaSajtLegtöbbször szomszédok (75 pont)cpp17Partially correct 73/7514ms4872 KiB
#include <bits/stdc++.h>
using namespace std;

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]++;
  }

  auto cmp = [](auto& p1, auto& p2) { return p1.second < p2.second; };

  auto [a, b] = *max_element(min_more_ind_cnt.begin(), min_more_ind_cnt.end(), cmp);
  auto [c, d] = *max_element(max_less_ind_cnt.begin(), max_less_ind_cnt.end(), cmp);

  cout << a << ' ' << b << '\n';
  cout << c << ' ' << d << '\n';
}
SubtaskSumTestVerdictTimeMemory
base73/75
1Accepted0/03ms1704 KiB
2Accepted0/013ms2676 KiB
3Partially correct1/23ms2072 KiB
4Partially correct1/23ms2284 KiB
5Accepted4/42ms2500 KiB
6Accepted4/42ms2584 KiB
7Accepted3/33ms2684 KiB
8Accepted4/43ms2712 KiB
9Accepted4/43ms3072 KiB
10Accepted4/44ms3292 KiB
11Accepted4/43ms3248 KiB
12Accepted4/44ms3688 KiB
13Accepted4/44ms3740 KiB
14Accepted4/44ms3912 KiB
15Accepted4/44ms4108 KiB
16Accepted4/46ms4316 KiB
17Accepted4/47ms4232 KiB
18Accepted4/48ms4156 KiB
19Accepted4/414ms4736 KiB
20Accepted4/414ms4804 KiB
21Accepted4/414ms4800 KiB
22Accepted4/414ms4872 KiB