40302023-03-09 12:30:41Error42Kártyajátékcpp17Accepted 30/3035ms6640 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define ll long long
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll n,k;
    cin>>n>>k;
    vector<ll>vec(k);
    deque<ll>q;
    for(ll i = 0; i < k; i++)
    {
        cin>>vec[i];
        q.push_front(vec[i]);
    } 
    sort(q.begin(), q.end());

    ll db = 0;
    for(ll i = 0; i < k; i++)
    {
        if(!q.empty() && q.front() < vec[i])
        {
            while (!q.empty() && q.front() != vec[i]) q.pop_front();
            db++;
        }
        if(!q.empty() && q.front() == vec[i]) q.pop_front();
    }
    cout<<db<<"\n";
}
/*
25 7
1 8 3 15 4 20 16
*/
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1824 KiB
2Accepted0/035ms5076 KiB
3Accepted1/12ms2108 KiB
4Accepted1/13ms2236 KiB
5Accepted1/12ms2344 KiB
6Accepted2/23ms2692 KiB
7Accepted2/23ms2908 KiB
8Accepted2/23ms3120 KiB
9Accepted1/117ms4900 KiB
10Accepted2/226ms6204 KiB
11Accepted3/325ms6228 KiB
12Accepted3/326ms6528 KiB
13Accepted1/135ms6640 KiB
14Accepted2/235ms6516 KiB
15Accepted3/332ms6516 KiB
16Accepted3/335ms6640 KiB
17Accepted3/335ms6580 KiB