56312023-08-29 13:21:07TomaSajtLegtöbbször szomszédok (75 pont)cpp17Partially correct 73/7514ms8620 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;
}
SubtaskSumTestVerdictTimeMemory
base73/75
1Accepted0/03ms1972 KiB
2Accepted0/014ms3412 KiB
3Partially correct1/23ms2820 KiB
4Partially correct1/22ms2912 KiB
5Accepted4/43ms3076 KiB
6Accepted4/43ms3204 KiB
7Accepted3/33ms3432 KiB
8Accepted4/43ms3644 KiB
9Accepted4/43ms4152 KiB
10Accepted4/44ms4168 KiB
11Accepted4/44ms4312 KiB
12Accepted4/44ms4752 KiB
13Accepted4/44ms4892 KiB
14Accepted4/44ms4892 KiB
15Accepted4/44ms5256 KiB
16Accepted4/46ms5820 KiB
17Accepted4/48ms5804 KiB
18Accepted4/48ms6256 KiB
19Accepted4/414ms7116 KiB
20Accepted4/414ms7512 KiB
21Accepted4/414ms7780 KiB
22Accepted4/414ms8620 KiB