# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
978949 | Amaarsaa | Job Scheduling (CEOI12_jobs) | C++14 | 187 ms | 17672 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
int a[100004] = {0}, n, d;
vector < ll > v[100004];
bool can(int mid) {
int i, s;
priority_queue < pair <int,int> , vector<pair<int,int>>, greater<pair<int,int>> > pq;
for (i = 1; i <= n; i ++) {
s = mid;
pq.push({i + d, a[i]});
while (s > 0) {
if ( pq.empty()) break;
pair <int,int> P = pq.top();
pq.pop();
if ( P.second < i) return 0;
if ( s >= P.second) {
s -= P.second;
}
else {
P.second -= s;
s= 0;
pq.push(P);
}
}
}
if ( pq.empty()) return 1;
return 0;
}
void Ans(int mid) {
int i, s;
priority_queue < pair <int,int> , vector<pair<int,int>>, greater<pair<int,int>> > pq;
for (i = 1; i <= n; i ++) {
s = mid;
pq.push({i + d, a[i]});
while (s > 0) {
if ( pq.empty()) break;
pair <int,int> P = pq.top();
pq.pop();
if ( s >= P.second) {
for (int j = 0; j < P.second; j ++) {
cout << v[P.first - d].back() << " ";
v[P.first - d].pop_back();
}
s -= P.second;
}
else {
for (int j = 0; j < s; j ++) {
cout << v[P.first - d].back() << " ";
v[P.first - d].pop_back();
}
P.second -= s;
s = 0;
pq.push(P);
}
}
cout << "0 " << endl;
}
return ;
}
int main() {
// freopen("moocast.in", "r", stdin);
// freopen("moocast.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
int m, i,x, lo, hi, mid;
cin >> n >> d >> m;
for (i = 1; i <= m; i ++) {
cin >> x;
v[x].push_back(i);
a[x] ++;
}
lo = 1;
hi = m;
while (lo < hi) {
mid = (lo + hi)/2;
if ( can(mid)) lo = mid + 1;
else hi = mid;
}
cout << lo + 1 << endl;
Ans(lo + 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |