//Copyright © 2021 Youngmin Park. All rights reserved.
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpi = vector<pii>;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
using ld = long double;
#define all(v) (v).begin(), (v).end()
#define ar array
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define REP(a) F0R(_, a)
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353;
const ld PI = acos((ld)-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <typename T>
bool ckmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
os << '{';
string sep;
for (const T &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
void dbg_out()
{
cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif
struct chash
{
static uint64_t splitmix64(uint64_t x)
{
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
size_t operator()(pair<uint64_t,uint64_t> x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);
}
};
void setIO(string s)
{
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
void solve()
{
int n, m, d;
cin >> n >> d >> m;
vi a(n+1);
vector<vi> b(n+1);
FOR(i, 1, 1+m){
int x;
cin >> x;
a[x]++;
b[x].pb(i);
}
int l = 1, r = m, ans = 1;
while(l<=r){
int mid = (l+r)/2;
deque<pii> todo;
int delay = 0;
for (int i = 1; i<=n;i++){
todo.pb({i, a[i]});
int work = mid;
while(work&&sz(todo)){
auto [day, num] = todo.front(); todo.pop_front();
int val = min(num, work);
work -= val, num -= val;
ckmax(delay, i-day);
if (num) todo.push_front({day, num});
}
}
// dbg(delay, mid);
if (delay<=d) ans = mid, r = mid - 1;
else l = mid + 1;
}
cout << ans << "\n";
int id = 0;
FOR(i, 1, n+1){
while(id<=n&&sz(b[id])==0)id++;
vi tmp;
if (id<=i){
while(sz(tmp)<ans&&id<=i){
while(id<=i&&sz(b[id])==0)id++;
if (id<=i){
tmp.pb(b[id].back());
b[id].pop_back();
}
}
}
tmp.pb(0);
FOR(j, 0, sz(tmp)) cout << tmp[j] << " \n"[j==sz(tmp)-1];
}
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int testcase=1;
// cin >> testcase;
while (testcase--)
{
solve();
}
}
Compilation message
jobs.cpp: In function 'void setIO(std::string)':
jobs.cpp:96:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:97:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
2048 KB |
Output is correct |
2 |
Correct |
16 ms |
2044 KB |
Output is correct |
3 |
Correct |
16 ms |
2044 KB |
Output is correct |
4 |
Correct |
16 ms |
2024 KB |
Output is correct |
5 |
Correct |
17 ms |
2040 KB |
Output is correct |
6 |
Correct |
17 ms |
2044 KB |
Output is correct |
7 |
Correct |
17 ms |
2044 KB |
Output is correct |
8 |
Correct |
17 ms |
1952 KB |
Output is correct |
9 |
Correct |
35 ms |
4480 KB |
Output is correct |
10 |
Correct |
36 ms |
4440 KB |
Output is correct |
11 |
Correct |
16 ms |
1484 KB |
Output is correct |
12 |
Correct |
31 ms |
2592 KB |
Output is correct |
13 |
Correct |
45 ms |
4548 KB |
Output is correct |
14 |
Correct |
79 ms |
5992 KB |
Output is correct |
15 |
Correct |
75 ms |
6800 KB |
Output is correct |
16 |
Correct |
105 ms |
8632 KB |
Output is correct |
17 |
Correct |
149 ms |
10584 KB |
Output is correct |
18 |
Correct |
119 ms |
10504 KB |
Output is correct |
19 |
Correct |
151 ms |
13888 KB |
Output is correct |
20 |
Correct |
124 ms |
10540 KB |
Output is correct |