18652022-12-06 10:01:05kdbLegtöbbször szomszédok (75 pont)cpp11Wrong answer 18/7513ms7072 KiB
#include <iostream>
#include <vector>
using namespace std;

std::ostream& operator<<(std::ostream& os, const std::vector<pair<int, int>>& input)
{
    for (auto const& i : input) {
        os << i.first << " " << i.second << endl;
    }
    return os;
}

int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> vec;
    for (int i = 0; i < m-1; i++)
    {
        int a;
        cin >> a;
        vec.push_back(make_pair(a, 0));
    }
    int x;
    cin >> x;
    vec.push_back(make_pair(-1, 0));
    for (int i = 0; i < n - m; i++)
    {
        int a;
        cin >> a;
        vec.push_back(make_pair(a, 0));
    }
    int elotte = 0, elotteHely = 0, utana = 10001, utanaHely = 0;
    for (int i = 0; i < n -1; i++)
    {
        if (vec[i].first > x && vec[i].first < utana)
        {
            utana = vec[i].first;
            utanaHely = i;
            vec[utanaHely].second++;
        }
        else
        {
            if(i>=m-1)
            vec[utanaHely].second++;
        }
        if (vec[i].first <x && vec[i].first > elotte)
        {
            elotte = vec[i].first;
            elotteHely = i;
            vec[elotteHely].second++;
        }
        else
        {
            if (i >= m - 1)
            vec[elotteHely].second++;
        }
    }
    int mini = 10001, minhely = 0, maxi = 0, maxhely = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (vec[i].second > mini && vec[i].first > x)
        {
            mini = vec[i].second;
            minhely = i;
        }
        if (vec[i].second > maxi && vec[i].first < x)
        {
            maxi = vec[i].second;
            maxhely = i;
        }
    }
    //cout << vec;
    cout << minhely +1 << " " << vec[minhely].second << endl << maxhely +1 << " " << vec[maxhely].second << endl;
    return 0;
}

/*
10 3
8 2 6 3 9 4 6 8 1 5
*/
SubtaskSumTestVerdictTimeMemory
base18/75
1Accepted0/03ms1704 KiB
2Accepted0/012ms4028 KiB
3Wrong answer0/22ms2340 KiB
4Wrong answer0/22ms2384 KiB
5Partially correct2/42ms2496 KiB
6Partially correct2/42ms2688 KiB
7Wrong answer0/32ms2896 KiB
8Partially correct2/42ms3104 KiB
9Wrong answer0/43ms3340 KiB
10Wrong answer0/43ms3684 KiB
11Wrong answer0/43ms3780 KiB
12Wrong answer0/44ms4188 KiB
13Wrong answer0/44ms4392 KiB
14Partially correct2/44ms4740 KiB
15Wrong answer0/44ms4832 KiB
16Wrong answer0/44ms5036 KiB
17Wrong answer0/46ms5588 KiB
18Wrong answer0/47ms5584 KiB
19Partially correct2/413ms6572 KiB
20Partially correct2/413ms6556 KiB
21Partially correct2/413ms6872 KiB
22Accepted4/413ms7072 KiB