Submission #572488

#TimeUsernameProblemLanguageResultExecution timeMemory
572488yhussain11Job Scheduling (CEOI12_jobs)C++17
54 / 100
258 ms23592 KiB
#include<bits/stdc++.h>

#define unless(x) if (!(x))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector<pi>;

// *INDENT-OFF*
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template<typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}'; }
template<size_t I = 0, typename... Tp> void __print_tup(const tuple<Tp...>& t) { cerr << get<I>(t); if constexpr(I < sizeof...(Tp) - 1) { cerr << ", "; __print_tup<I+1>(t); } }
template<typename... Tp> void __print(const tuple<Tp...>& t) { cerr << '{'; __print_tup(t); cerr << '}'; }
/* template<typename... Args> void __print(const tuple<Args...>& t) { cerr << '{'; apply([](auto&&... args) { ((cout << args << ','), ...); }, t); cerr << '}'; } */
template<typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
template<typename T> T ceil_div(T a, T b) { return (a + b - 1) / b; }
#ifdef LOCAL
#define dbg(x...) cerr << "\e[1;31m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[0m";
#else
#define dbg(x...)
#endif
// *INDENT-ON*

// YOU ARE ACTUALLY **SUPPOSED** TO READ THE FOLLOWING.
// Read the problem. Now Re-read the problem.
// Observe each constraint. Please do this. Notice each and every constraint.
// You have made many mistakes because you didn't read the constraint well enough.
// You are probably solving a harder version of the given problem.
// DO NOT OVERSOLVE.
// Do not look ahead for next problem. Solve the current problem.
// Do not look at standings.
// check overflow/underflow
// string(count, char)
// queue.push, queue.pop, queue.front, stack.push, stack.pop, stack.top
// string chk {x, y, x, y};
// string chk = string() + x + y + x + y;

void solve() {
    int n, d, m;
    cin >> n >> d >> m;
    vpi v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i].f;
        v[i].s = i;
    }
    sort(all(v));
    int lo = 1, hi = m;
    int mcnt = -1;
    while (lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        int mx = 0;
        for (int i = 1, j = 0; i <= n; i++) {
            int cnt = 0;
            for (; j < m && cnt < mid && v[j].f <= i; j++) {
                cnt++;
                ckmax(mx, i - v[j].f);
            }
        }
        if (mx <= d) {
            mcnt = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    vector<vector<int>> ans(n);
    for (int i = 1, j = 0; i <= n; i++) {
        int cnt = 0;
        for (; j < m && cnt < mcnt && v[j].f <= i; j++) {
            cnt++;
            ans[i].pb(v[j].s + 1);
        }
    }
    cout << mcnt << '\n';
    for (auto &x : ans) {
        for (auto &y : x) cout << y << " ";
        cout << 0 << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    /* cin >> t; */
    while (t--) {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...