Submission #896274

# Submission time Handle Problem Language Result Execution time Memory
896274 2024-01-01T07:25:19 Z akkshaysr Job Scheduling (CEOI12_jobs) C++17
100 / 100
191 ms 13904 KB
#include <bits/stdc++.h>
#define fr first
#define se second
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define repr(i,a,b) for(int i = a; i > (b); --i)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define IN(i,l,r) (l<i&&i<r)
#define pb push_back
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef long long ll;
const int U = 1e6+2;
int N,D,M;
pi job[U];

bool check(int m){
    int t=0;
    rep(day,1,N+1){
        rep(i,0,m){
            if(job[t].fr > day){
                break;
            }
            if(job[t].fr + D >= day){
                ++t;
            }else{
                return false;
            }
            if(t==M) return true;
        }
    }
    return false;
}

int main(){
    cin.tie(0)->sync_with_stdio(false);
    cin >> N >> D >> M;
    rep(i,0,M){
        cin >> job[i].fr;
        job[i].se = i+1;
    }
    sort(job,job+M);
    int lo=1,hi=M;
    vector<vi> s;
    while(lo < hi){
        ll m = (lo+hi)/2;
        if(check(m)) hi = m;
        else lo = m+1;
    }
    cout << hi << '\n';
    int t = 0;
    rep(day,1,N+1){
        rep(i,0,hi){
            if(job[t].fr > day or t==M){
                break;
            }
            if(job[t].fr + D >= day){
                cout << job[t].se << ' ';
                ++t;
            }
        }
        cout << "0\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3164 KB Output is correct
2 Correct 14 ms 3164 KB Output is correct
3 Correct 13 ms 3164 KB Output is correct
4 Correct 13 ms 3164 KB Output is correct
5 Correct 13 ms 3204 KB Output is correct
6 Correct 13 ms 3164 KB Output is correct
7 Correct 13 ms 3416 KB Output is correct
8 Correct 13 ms 3208 KB Output is correct
9 Correct 21 ms 3420 KB Output is correct
10 Correct 21 ms 3408 KB Output is correct
11 Correct 21 ms 3280 KB Output is correct
12 Correct 41 ms 3964 KB Output is correct
13 Correct 67 ms 6740 KB Output is correct
14 Correct 86 ms 7252 KB Output is correct
15 Correct 101 ms 8020 KB Output is correct
16 Correct 127 ms 10836 KB Output is correct
17 Correct 150 ms 11376 KB Output is correct
18 Correct 169 ms 12144 KB Output is correct
19 Correct 191 ms 13904 KB Output is correct
20 Correct 150 ms 11604 KB Output is correct