# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
527610 | _karan_gandhi | Job Scheduling (CEOI12_jobs) | C++17 | 1095 ms | 35640 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "
void solve() {
ll int n, d, m; cin >> n >> d >> m;
vector<pair<ll int, ll int>> arr(m); for (ll int i = 0; i < m; i++) cin >> arr[i].first;
for (ll int i = 0; i < m; i++) arr[i].second = i + 1;
sort(all(arr));
auto possible = [&](ll int x) {
// check if it is possible to complete the jobs with x machines
multiset<ll int> s;
for (ll int i = 0; i < x; i++) {
s.insert(arr[i].first);
}
for (ll int i = x; i < m; i++) {
ll int last = *s.begin();
s.erase(s.find(last));
if (last + 1 - arr[i].first > d) return false;
s.insert(max(last + 1, arr[i].first));
}
return true;
};
// cout << pl(possible(1)) << endl;
ll int hi = m, lo = 1;
ll int ans = 0;
while (hi >= lo) {
ll int mid = (hi + lo) / 2;
if (possible(mid)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << endl;
// find a way to get answer
vector<vector<ll int>> days(n + 1);
multiset<ll int> s;
for (ll int i = 0; i < ans; i++) {
// cout << pl(arr[i].second) << endl;
s.insert(arr[i].first);
days[arr[i].first - 1].push_back(arr[i].second);
}
for (ll int i = ans; i < m; i++) {
ll int last = *s.begin();
s.erase(s.find(last));
s.insert(max(last + 1, arr[i].first));
days[max(last + 1, arr[i].first) - 1].push_back(arr[i].second);
}
for (ll int i = 0; i < n; i++) {
for (ll int a : days[i]) cout << a << ' ';
cout << 0 << endl;
}
}
int main() {
// freopen("socdist.in", "r", stdin);
// freopen("socdist.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
// ll int t; cin >> t;
// while (t--)
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |