Submission #1370448

#TimeUsernameProblemLanguageResultExecution timeMemory
1370448otariusJob Scheduling (CEOI12_jobs)C++20
85 / 100
52 ms14804 KiB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count());

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 1e5 + 15;
const int maxM = 1e6 + 15;

vector<int> pos[maxN];
int n, d, m, arr[maxM];
bool check(int p) {
    int j = 1, did = 0, now;
    for (int i = 1; i <= n; i++) {
        now = p;
        while (j <= i && (int)pos[j].size() - did <= now) { now -= (int)pos[j].size() - did; j++; did = 0; }
        if (i - j >= d) return 0;

        if (j <= i) did = now; else did = 0;
    }

    return 1;
}
void solve() {
    cin >> n >> d >> m;
    for (int i = 1; i <= m; i++) {
        cin >> arr[i]; pos[arr[i]].pb(i);
    }

    int l = 1, r = m, m, ans = -1;
    while (l <= r) {
        m = (l + r) / 2;
        if (check(m)) {
            ans = m; r = m - 1;
        } else l = m + 1;
    }

    cout << ans << '\n'; int cur = 1; 
    for (int i = 1; i <= n; i++) {
        int left = ans;
        while (left && cur <= i) {
            int cnt = min(left, (int)pos[cur].size()); left -= cnt;
            while (cnt--) {
                cout << pos[cur].back() << ' '; pos[cur].pop_back();
            }

            if (pos[cur].size() == 0) ++cur;
        }

        cout << "0\n";
    }
}
int32_t main() { 
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...