#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#define mp make_pair
using pi = pair<int, int>;
using vi = vector<int>;
int N, D, M;
pair<bool, vector<vi>> isFeasible(const vector<pi> &jobs, int machineCount)
{
vector<vi> schedule(N);
int reqNum = 0;
for (int day = 1; day <= N; day++)
{
for (int j = 0; j < machineCount; j++)
{
if (jobs[reqNum].first > day)
break;
if (jobs[reqNum].first + D >= day)
schedule[day - 1].push_back(jobs[reqNum++].second);
else
return mp(false, schedule);
if (reqNum == M)
return mp(true, schedule);
}
}
return mp(false, schedule);
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
cin >> N >> D >> M;
vector<pi> jobs(M);
for (int i = 0; i < M; i++)
{
int day;
cin >> day;
jobs[i] = mp(day, i + 1);
}
sort(all(jobs));
vector<vi> result;
int l = 1, r = M;
while (l < r)
{
int machineNum = (l + r) / 2;
pair<bool, vector<vi>> curResult = isFeasible(jobs, machineNum);
if (curResult.first)
{
r = machineNum;
result = curResult.second;
}
else
l = machineNum + 1;
}
cout << l << "\n";
for (int i = 0; i < N; i++)
{
for (int &idx : result[i])
cout << idx << " ";
cout << 0 << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
2984 KB |
Output is correct |
2 |
Correct |
32 ms |
2972 KB |
Output is correct |
3 |
Correct |
29 ms |
2976 KB |
Output is correct |
4 |
Correct |
29 ms |
3044 KB |
Output is correct |
5 |
Correct |
31 ms |
2964 KB |
Output is correct |
6 |
Correct |
29 ms |
2976 KB |
Output is correct |
7 |
Correct |
31 ms |
2980 KB |
Output is correct |
8 |
Correct |
33 ms |
2968 KB |
Output is correct |
9 |
Correct |
76 ms |
9672 KB |
Output is correct |
10 |
Correct |
92 ms |
9708 KB |
Output is correct |
11 |
Correct |
39 ms |
2716 KB |
Output is correct |
12 |
Correct |
75 ms |
4940 KB |
Output is correct |
13 |
Correct |
118 ms |
8692 KB |
Output is correct |
14 |
Correct |
188 ms |
10800 KB |
Output is correct |
15 |
Correct |
198 ms |
10868 KB |
Output is correct |
16 |
Correct |
264 ms |
16032 KB |
Output is correct |
17 |
Correct |
308 ms |
18832 KB |
Output is correct |
18 |
Correct |
347 ms |
23260 KB |
Output is correct |
19 |
Correct |
433 ms |
26404 KB |
Output is correct |
20 |
Correct |
311 ms |
18844 KB |
Output is correct |