1740D - Knowledge Cards - CodeForces Solution


constructive algorithms data structures greedy math *1500

Please click on ads to support us..

Python Code:

                                                                                                                                                                                                                                                                                                            

import sys
input = sys.stdin.readline

from heapq import *

for _ in range(int(input())):
    n, m, k = map(int, input().split())
    l = list(map(int, input().split()))
    boo = True
    mx = n * m - 3
        t = k
    h = []
    for i in l:
                while h and -h[0] == t:
            heappop(h)
            t -= 1
        if len(h) >= mx: boo = False;break
        if i == t:
            t -= 1
        else:
            heappush(h, -i)
    if boo:print("YA")
    else:print("TIDAK")

C++ Code:

#include <bits/stdc++.h>
#define ll long long
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define D 8

using namespace std;


template<typename T>
ostream& operator<<(ostream &out, vector<T> cont)
{
    for(auto it = cont.begin(); it != cont.end(); it++)
        out << *it << (it != cont.end()-1 ? ' ' : '\n');
    return out;
}

template<typename T>
ostream& operator<<(ostream &out, vector<vector<T>> cont)
{
    for(auto it = cont.begin(); it != cont.end(); it++)
        out << *it;
    return out;
}


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll t;
    cin >> t;

    FOR(i, t)
    {
        ll n, m, k, j=0;
        cin >> n >> m >> k;
        set<ll> s;
        string res = "ya\n";
        vector<ll> v(k);
        FOR(i, k) cin >> v[i];

        for(ll i = k; i>0; i--)
        {
            while (s.count(i) == 0)
            {
                s.insert(v[j++]);
                if(s.size() > n*m-3) 
                {
                    res = "tidak\n";
                }
            }
            s.erase(i);           
        }
        cout << res;
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number