Submission #860695

#TimeUsernameProblemLanguageResultExecution timeMemory
860695coldyJob Scheduling (CEOI12_jobs)C++14
100 / 100
359 ms20292 KiB
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int n, d, m;
vector <int> p[(int)1e5 + 1], ans[(int)1e5 + 1];
bool ok(int x){
    for(int i = 1; i <= n; i++) ans[i].clear();
    for(int i = 1, idx = 1 ; i <= n; idx = max(idx, ++i)){
        for(int id: p[i]){
            if(ans[idx].size() == x) idx++;
            if(idx > i + d) return 0;
            ans[idx].push_back(id);
        }
    }
    return 1;
}
int main(){
    cin>>n>>d>>m;
 
    for(int i = 0; i < m; i++){
        int x;
        cin>>x;
        p[x].push_back(i + 1);
    }
 
    int lo = 1;
    int hi = m;
    while(lo < hi){
        int mid = (lo + hi)/2;
        if(ok(mid)) hi = mid;
        else lo = mid + 1;
    }
    ok(lo);
	cout<<lo<<endl;
    for(int i = 1; i <= n; i++){
        for(int id: ans[i]){
            cout<<id<<" ";
        }
        cout<<0<<"\n";
    }
}

Compilation message (stderr)

jobs.cpp: In function 'bool ok(int)':
jobs.cpp:10:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   10 |             if(ans[idx].size() == x) idx++;
      |                ~~~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...