結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-11-12 09:53:21 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,089 bytes |
| コンパイル時間 | 1,982 ms |
| コンパイル使用メモリ | 86,092 KB |
| 実行使用メモリ | 78,880 KB |
| 最終ジャッジ日時 | 2024-09-17 15:16:49 |
| 合計ジャッジ時間 | 9,257 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 TLE * 1 -- * 3 |
ソースコード
import java.util.*;
public class Main {
static final int MOD = 1000000007;
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
long d = sc.nextLong();
int q = sc.nextInt();
PriorityQueue<Work> queue = new PriorityQueue<>();
PriorityQueue<Work> next = new PriorityQueue<>();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < q; i++) {
queue.add(new Work(sc.nextLong(), sc.nextLong()));
Work prev = queue.poll();
long max = prev.getCount();
while (queue.size() > 0) {
Work x = queue.poll();
if (prev.end >= x.start - 1) {
prev.add(x);
} else {
next.add(prev);
prev = x;
}
max = Math.max(max, prev.getCount());
}
sb.append(max).append("\n");
next.add(prev);
PriorityQueue<Work> tmp = next;
next = queue;
queue = tmp;
}
System.out.print(sb);
}
static class Work implements Comparable<Work> {
long start;
long end;
public Work(long start, long end) {
this.start = start;
this.end = end;
}
public int compareTo(Work another) {
if (start == another.start) {
if (end == another.end) {
return 0;
} else if (end < another.end) {
return -1;
} else {
return 1;
}
} else {
if (start == another.start) {
return 0;
} else if (start < another.start) {
return -1;
} else {
return 1;
}
}
}
public long getCount() {
return end - start + 1;
}
public void add(Work another) {
start = Math.min(start, another.start);
end = Math.max(end, another.end);
}
public String toString() {
return "start:" + start + " end:" + end;
}
}
}
htensai