Submission #1366407

#TimeUsernameProblemLanguageResultExecution timeMemory
1366407darkdevilvaqifJob Scheduling (CEOI12_jobs)C++20
100 / 100
30 ms876 KiB
/*
  _      __        __         __        ____                    ___    _                   __
 | | /| / / ___ _ / /_ ____  / /       / __ \  ___  ___        / _ \  (_) ___  ____ ___   / /
 | |/ |/ / / _ `// __// __/ / _ \     / /_/ / / _ \/ -_)      / ___/ / / / -_)/ __// -_) /_/ 
 |__/|__/  \_,_/ \__/ \__/ /_//_/     \____/ /_//_/\__/      /_/    /_/  \__/ \__/ \__/ (_)  
                                                                                             
*/

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define all(v) v.begin(), v.end()
#define allr(v, l, r) v.begin() + l, v.begin() + r + 1
#define rall(v) v.rbegin(), v.rend()
#define rallr(v, l, r) v.rbegin() + ((int)v.size() - 1 - r), v.rbegin() + ((int)v.size() - l)
#define endl "\n"
#define newline cout << endl;
using namespace std;
 
// constants
const int INF = 1e9;

// functions

// structs

// globals

// notes
/*
 -stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH

continue - skip the rest in the loop
*/
 
void solve()
{
    int n, D, m;
    cin >> m >> D >> n;
    vector <int> a(m + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        
        a[x]++;
    }

    auto check = [&](int machines) -> bool
    {
        queue <int> q;
        for (int i = 1; i <= m; i++)
        {
            int left = machines;
            while (!q.empty() && left)
            {
                if (q.front() + D < i)
                {
                    return false;
                }
                q.pop();
                left--;
            }
            int x = max(0, a[i] - left);
            while (x)
            {
                q.push(i);
                x--;
            }
        }
        return q.empty();
    };

    int L = 1, R = n;
    while (L <= R)
    {
        int mid = (L + R) / 2;
        if (check(mid))
        {
            R = mid - 1;
        }
        else
        {
            L = mid + 1;
        }
    }

    cout << L;
    for (int i = 1; i <= m; i++)
    {
        cout << endl << 0;
    }
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int testcount = 1;
    // cin >> testcount;
    while (testcount--)
    {
        solve();
        newline
    }
}

/*
$$$$$$$$\ $$$$$$$$\ 
$$  _____|\____$$  |
$$ |          $$  / 
$$$$$\       $$  /  
$$  __|     $$  /   
$$ |       $$  /    
$$$$$$$$\ $$$$$$$$\ 
\________|\________|
*/
#Result Execution timeMemoryGrader output
Fetching results...