Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions 0224LJH/202512/02 BOJ 파티가 좋아 파티가 좋아.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();
static int partyCnt,day;
static HashSet<Party> set;

static class Party{
int start, end,idx;

public Party(int start, int end, int idx) {
this.idx = idx;
this.start = start;
this.end = end;
}
}

public static void main(String[] args) throws IOException {
day = 0;
while(true) {
partyCnt = Integer.parseInt(br.readLine());
if (partyCnt == 0 ) break;
init();
process();
}
print();

}

private static void init() throws IOException{
day++;
set = new HashSet<>();
for (int i = 0; i < partyCnt; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
set.add(new Party(start, end,i));
}
}

private static void process() throws IOException {
// 23시부터 시작, 제일 늦게 끝나는것부터 찾아서 넣기.
int cnt = 0;

for (int i = 23; i >= 8; i--) {

for (int j = 0; j < 2; j++) {
int maxDay = 0;
Party target = null;
for (Party p: set) {
if (p.end > i && p.start <= i ) {
if (maxDay < p.start) {
maxDay = p.start;
target = p;
}
}
}

if (target != null) {
set.remove(target);
cnt++;
}
}
}

String ans = String.format("On day %d Emma can attend as many as %d parties.\n",day,cnt);
sb.append(ans);

}

private static void print() {
System.out.print(sb.toString());
}

}
```