#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int len1 = 1e6+5, len2 = 1e5+5;
int n, d, m, st[len1];
vector<int> out[len2], day[len2];
queue<int> myq;
bool check(int k){
while (!myq.empty())
myq.pop();
for (int i = 1; i <= n; i++){
out[i].clear();
for (int j = 0; j < day[i].size(); j++)
myq.push(day[i][j]);
int rem = k;
while (!myq.empty() && rem){
int cur = myq.front();
myq.pop();
rem--;
//printf("cur = %d, val = %d\n", cur, st[cur]);
if (i > st[cur]+d)
return false;
out[i].pb(cur);
}
}
return (myq.empty());
}
int bs(){
int l = 1, r = m, ans = 0;
while (l <= r){
int mid = (l+r)/2;
//printf("l = %d, r = %d, mid = %d\n", l, r, mid);
if (check(mid))
r = mid-1, ans = mid;
else
l = mid+1;
}
return ans;
}
int main(){
scanf("%d %d %d", &n, &d, &m);
for (int i = 1; i <= m; i++){
scanf("%d", &st[i]);
day[st[i]].pb(i);
//printf("i = %d, st = %d\n", i, st[i]);
}
int ans = bs();
check(ans);
printf("%d\n", ans);
for (int i = 1; i <= n; i++){
for (int j = 0; j < out[i].size(); j++)
printf("%d ", out[i][j]);
printf("0\n");
}
return 0;
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/
Compilation message
jobs.cpp: In function 'bool check(int)':
jobs.cpp:17:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < day[i].size(); j++)
~~^~~~~~~~~~~~~~~
jobs.cpp: In function 'int main()':
jobs.cpp:66:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < out[i].size(); j++)
~~^~~~~~~~~~~~~~~
jobs.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &d, &m);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &st[i]);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
7792 KB |
Output is correct |
2 |
Correct |
34 ms |
7792 KB |
Output is correct |
3 |
Correct |
33 ms |
7792 KB |
Output is correct |
4 |
Correct |
34 ms |
7792 KB |
Output is correct |
5 |
Correct |
33 ms |
7780 KB |
Output is correct |
6 |
Correct |
34 ms |
7792 KB |
Output is correct |
7 |
Correct |
33 ms |
7800 KB |
Output is correct |
8 |
Correct |
37 ms |
7792 KB |
Output is correct |
9 |
Correct |
42 ms |
7416 KB |
Output is correct |
10 |
Correct |
41 ms |
7544 KB |
Output is correct |
11 |
Correct |
40 ms |
7416 KB |
Output is correct |
12 |
Correct |
75 ms |
9848 KB |
Output is correct |
13 |
Correct |
145 ms |
13432 KB |
Output is correct |
14 |
Correct |
245 ms |
17476 KB |
Output is correct |
15 |
Correct |
198 ms |
17912 KB |
Output is correct |
16 |
Correct |
383 ms |
21852 KB |
Output is correct |
17 |
Correct |
530 ms |
26384 KB |
Output is correct |
18 |
Correct |
423 ms |
25180 KB |
Output is correct |
19 |
Correct |
530 ms |
26724 KB |
Output is correct |
20 |
Correct |
485 ms |
26232 KB |
Output is correct |