# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
263389 | DS007 | Job Scheduling (CEOI12_jobs) | C++14 | 1098 ms | 11052 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>
using namespace std;
#define int long long
const int N = 1e5, M = 1e6;
int a[M], n, d, m;
bool check(int mid) {
queue<int> q;
for (int i = 1, p = 0; i <= n; i++) {
while (p < m && a[p] == i)
q.push(a[p++]);
for (int j = 0; j < mid && !q.empty(); j++) {
if (i - q.front() > d)
return false;
q.pop();
}
}
return true;
}
int solveTestCase() {
cin >> n >> d >> m;
for (int i = 0; i < m; i++) cin >> a[i];
sort(a, a + m);
int l = 1, h = M, ans = M;
while (l <= h) {
//cerr << l << " " << h << "\n";
int mid = (l + h) / 2;
if (check(mid))
ans = mid, h = mid - 1;
else
l = mid + 1;
}
cout << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--)
solveTestCase();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |