# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927915 | megaminion | Job Scheduling (CEOI12_jobs) | C++17 | 1046 ms | 32928 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define ins insert
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define endl '\n'
using namespace std;
using ll = long long;
const int M = 1e6;
const int N = 1e5;
int n, d, m;
int a[M], mp[N+1];
vector<int> v[N+1];
vector<int> p[N+1];
bool ok(int x, bool flag)
{
bool ret = true;
multiset<int> s;
for(int i = 1; i <= n; ++i)
{
v[i].clear();
for(int j = 0; j < mp[i]; ++j)
{
s.ins(i);
}
for(int j = 0; j < x; ++j)
{
if(s.empty()) break;
ret &= i - *s.begin() <= d;
if(flag)
{
v[i].pb(p[*s.begin()].back());
p[*s.begin()].pop_back();
}
s.erase(s.begin());
}
}
return ret;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>d>>m;
for(int i = 0; i < m; ++i)
{
cin>>a[i];
mp[a[i]]++;
p[a[i]].pb(i+1);
}
int L = 1, R = 1e7, mid;
while(L < R)
{
mid = L + (R - L) / 2;
if(ok(mid, false))
{
R = mid;
}
else
{
L = mid+1;
}
}
cout<<L<<endl;
assert(ok(L, true));
for(int i = 1; i <= n; ++i)
{
for(int j = 0; j < sz(v[i]); ++j)
{
cout<<v[i][j];
if(j + 1 != sz(v[i])) cout<<" ";
else cout<<" 0";
}
if(v[i].empty())
{
cout<<"0";
}
if(i != n) cout<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |