#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pi3 = pair<int,pii>;
#define ON(n , k) ( (n) | ( 1 << (k) ))
#define OFF(n ,k) ( (n) & ( ~( 1 << (k))))
#define ISON(n ,k) ( ( (n)>>(k) ) & (1) )
#define F first
#define S second
const int N = 2e5+5;
const int mod = 1e9+7;
const int INF = 1e9+9;
const double PI = 3.1415926536;
int dx[10] = {0, 0, 1, -1, 1, 1, -1, -1, 0};
int dy[10] = {1, -1, 0, 0, 1, -1, 1, -1, 0};
char str[N];
int n, d, m;
vector<pii>v;
bool cmp(pii A, pii B)
{
if(A.S == B.S)
{
return B.F < A.F;
}
return A.S < B.S;
}
bool ok(int mid)
{
int j = 1, i = 0;
while(i < m)
{
int s = i;
for(i; i < s + mid; i++)
{
if( (j - v[i].S) > d)return false;
}
j++;
}
return true;
}
void solve()
{
scanf("%d%d%d", &n, &d, &m);
for(int i = 1; i <= m; i++)
{
int x;
scanf("%d", &x);
v.push_back({i, x});
}
sort(v.begin(), v.end(), cmp);
int l = 0, r = m+2, mid;
while(l + 1 < r)
{
mid = l + (r - l)/2;
if(ok(mid))
{
r = mid;
}
else
{
l = mid;
}
}
printf("%d\n", r);
int j = 1, i = 0;
while(j <= n)
{
int s = i;
for(i; i < s + mid && i < m; i++)
{
printf("%d ", v[i].F);
}
j++;
printf("0\n");
}
}
int main()
{
//freopen("", "r", stdin);
//freopen("", "w", stdout);
/*
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
*/
int T;
T = 1 ;
//scanf("%d" , &T);
while(T--)
{
// init();
solve();
}
return 0;
}
Compilation message
jobs.cpp: In function 'bool ok(int)':
jobs.cpp:45:13: warning: statement has no effect [-Wunused-value]
45 | for(i; i < s + mid; i++)
| ^
jobs.cpp: In function 'void solve()':
jobs.cpp:94:13: warning: statement has no effect [-Wunused-value]
94 | for(i; i < s + mid && i < m; i++)
| ^
jobs.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d%d%d", &n, &d, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
jobs.cpp:94:22: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
94 | for(i; i < s + mid && i < m; i++)
| ~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
2120 KB |
Output isn't correct |
2 |
Incorrect |
23 ms |
2084 KB |
Output isn't correct |
3 |
Incorrect |
22 ms |
2076 KB |
Output isn't correct |
4 |
Incorrect |
24 ms |
2116 KB |
Output isn't correct |
5 |
Incorrect |
21 ms |
2048 KB |
Output isn't correct |
6 |
Incorrect |
23 ms |
2124 KB |
Output isn't correct |
7 |
Incorrect |
25 ms |
2108 KB |
Output isn't correct |
8 |
Incorrect |
23 ms |
2040 KB |
Output isn't correct |
9 |
Incorrect |
32 ms |
2236 KB |
Output isn't correct |
10 |
Incorrect |
32 ms |
2180 KB |
Output isn't correct |
11 |
Incorrect |
30 ms |
2084 KB |
Output isn't correct |
12 |
Incorrect |
61 ms |
3960 KB |
Output isn't correct |
13 |
Incorrect |
94 ms |
5808 KB |
Output isn't correct |
14 |
Incorrect |
121 ms |
8240 KB |
Output isn't correct |
15 |
Incorrect |
157 ms |
9712 KB |
Output isn't correct |
16 |
Incorrect |
182 ms |
12088 KB |
Output isn't correct |
17 |
Incorrect |
216 ms |
14080 KB |
Output isn't correct |
18 |
Incorrect |
253 ms |
15232 KB |
Output isn't correct |
19 |
Incorrect |
277 ms |
17264 KB |
Output isn't correct |
20 |
Incorrect |
265 ms |
13972 KB |
Output isn't correct |