제출 #374685

#제출 시각아이디문제언어결과실행 시간메모리
374685ritul_kr_singhJob Scheduling (CEOI12_jobs)C++17
100 / 100
344 ms20972 KiB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"

int n, d, m;
array<int, 2> a[1000000];

bool possible(int k){
    int j=0;
    for(int i=0; i<n; ++i){
        int curr=0;
        while(curr+1<=k and j<m and a[j][0]<=i+1 and i+1<=a[j][0]+d){
            ++j;
            ++curr;
        }
    }
    return j==m;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> d >> m;
    for(int i=0; i<m; ++i) cin >> a[i][0], a[i][1] = i;
    sort(a, a+m);
    int low = 1, high = 1e9;
    while(low<high){
        int mid = (low+high)/2;
        if(possible(mid)) high = mid;
        else low = mid+1;
    }
    cout << low nl;
    int j=0;
    for(int i=0; i<n; ++i){
        int curr=0;
        while(curr+1<=low and j<m and a[j][0]<=i+1){
            cout << a[j][1]+1 << ' ';
            ++j;
            ++curr;
        }
        cout << 0 nl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...