74032024-01-08 14:22:08CWMKártyajátékcpp17Wrong answer 29/3093ms6628 KiB
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
#define ll long long
int main()
{
    ll i1;
    int n;
    cin >> i1 >> n;
    vector<ll> ord(n);
    ll max = -1;
    ll Secmax = -1;
    ll SecmaxATP = -1;
    vector<ll> maxVec;
    int res = 0;
    for (size_t i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        ord[i] = a;
        if (a > max) {
            if(SecmaxATP==-1) maxVec.push_back(a);
            if (a == i1) {
                SecmaxATP = max;
                if (max == -1) {
                    max = i1;
                }
            }
            else {
                Secmax = a;
                max = a;
            }
        }
    }
    if (n==3 && Secmax == SecmaxATP) res--;
    if (maxVec.size() == 1) {
        if (n == 1) cout << 0;
        else cout << 1;
        return 0;
    }
    sort(ord.begin(), ord.end());
    if (maxVec[0] != ord[0]) res++;
    int insVec = 1;
    for (size_t i = 0; i < ord.size(); i++)
    {
        if (ord[i] == maxVec[insVec]) {
            if (i != insVec) {
                if (i == ord.size() - 1) {
                    res++;
                    break;
                }
                if (ord[i + 1] != maxVec[insVec + 1]) {
                    res++;
                }
            }
            insVec++;
        }
    }
    if (res == -1) res = 0;
    cout << res;
}
SubtaskSumTestVerdictTimeMemory
base29/30
1Accepted0/03ms1836 KiB
2Accepted0/093ms4648 KiB
3Accepted1/13ms2060 KiB
4Wrong answer0/13ms2100 KiB
5Accepted1/13ms2308 KiB
6Accepted2/23ms2524 KiB
7Accepted2/23ms2604 KiB
8Accepted2/23ms2600 KiB
9Accepted1/132ms3660 KiB
10Accepted2/248ms5256 KiB
11Accepted3/348ms5432 KiB
12Accepted3/348ms5348 KiB
13Accepted1/193ms4384 KiB
14Accepted2/292ms4960 KiB
15Accepted3/392ms6628 KiB
16Accepted3/393ms5724 KiB
17Accepted3/392ms5896 KiB