# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
306555 | updown1 | Job Scheduling (CEOI12_jobs) | Java | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.util.*;
import java.io.*;
public class Main {
static pair[] inp;
static int N, D, M;
// TLE && RTE
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("test.in"));
StringTokenizer st = new StringTokenizer(in.readLine());
M = Integer.parseInt(st.nextToken());
D = Integer.parseInt(st.nextToken());
N = Integer.parseInt(st.nextToken());
inp = new pair[N];
st = new StringTokenizer(in.readLine());
for (int i=0; i<N; ++i) {
inp[i] = new pair(Integer.parseInt(st.nextToken()), i+1);
}
Arrays.sort(inp);
int a=1, b=N;
while (a != b) {
int mid = (a+b)/2;
if (works(mid)) b = mid;
else a = mid+1;
}
System.out.println(a);
int at = 0;
for (int j=0; j<M; j++) {
int cnt = 0;
while (at != N && inp[at].val <= j && cnt <a) {
cnt++;
System.out.print(inp[at].index + " ");
at++;
}
System.out.println(0);
}
}
public static boolean works(int m) {
int day = 1;
int lef = m;
for (int i=0; i<N; i++) {
if (inp[i].val > day) {day=inp[i].val; lef = m;}
if (inp[i].val + D < day) return false;
lef--;
if (lef == 0) {day++; lef=m;}
}
return true;
}
public static class pair implements Comparable<pair> {
public int val, index;
public pair(int a, int b) {
this.val = a;
this.index = b;
}
@Override
public int compareTo(pair other) {
return val - other.val;
}
}
}