π·πΌλͺ¨μ¬λ΄μ κ°λ°μμ²π·πΌ
[JAVA/μ½λ©ν μ€νΈ] κ²°νΌμ λ³Έλ¬Έ
νμλ λ€μ λ¬μ κ²°νΌμ ν©λλ€.
νμλ κ²°νΌμ νΌλ‘μ°μ μ₯μλ₯Ό λΉλ € 3μΌκ° μ¬μ§ μκ³ νλ €κ³ ν©λλ€.
νΌλ‘μ°μ μ°Έμνλ μΉκ΅¬λ€ Nλͺ μ μ°Έμνλ μκ°μ 보λ₯Ό νμλ μΉκ΅¬λ€μκ² λ―Έλ¦¬ μꡬνμ΅λλ€.
κ° μΉκ΅¬λ€μ μμ μ΄ λͺ μμ λμ°©ν΄μ λͺ μμ λ λ κ²μΈμ§ νμμκ² μλ €μ£Όμμ΅λλ€.
νμλ μ΄ μ 보λ₯Ό λ°νμΌλ‘ νΌλ‘μ° μ₯μμ λμμ μ‘΄μ¬νλ μ΅λ μΈμμλ₯Ό ꡬνμ¬ κ·Έ μΈμμ μμ©ν μ μλ μ₯μλ₯Ό λΉλ¦¬λ €κ³ ν©λλ€. μ¬λ¬λΆμ΄ νμλ₯Ό λμμ£ΌμΈμ.
λ§μ½ ν μΉκ΅¬κ° μ€λ μκ° 13, κ°λμκ° 15λΌλ©΄ μ΄ μΉκ΅¬λ 13μ μ κ°μ νΌλ‘μ° μ₯μ μ‘΄μ¬νλ κ²μ΄κ³ 15μ μ κ°μλ μ‘΄μ¬νμ§ μλλ€κ³ κ°μ ν©λλ€.
μ λ ₯
첫째 μ€μ νΌλ‘μ°μ μ°Έμν μΈμμ N(5<=N<=100,000)μ΄ μ£Όμ΄μ§λλ€.
λ λ²μ§Έ μ€λΆν° Nμ€μ κ±Έμ³ κ° μΈμμ μ€λ μκ°κ³Ό κ°λ μκ°μ΄ μ£Όμ΄μ§λλ€.
μκ°μ 첫λ 0μλ₯Ό 0μΌλ‘ ν΄μ λ§μ§λ§λ λ°€ 12μλ₯Ό 72λ‘ νλ νμλΌμΈμΌλ‘ μ€λ μκ°κ³Ό κ°λ μκ°μ΄ μμ΄ μλ μ μλ‘ ννλ©λλ€.
μΆλ ₯
첫째 μ€μ νΌλ‘μ°μ₯μ λμμ μ‘΄μ¬νλ μ΅λ μΈμμ μΆλ ₯νμΈμ.
μμ μ λ ₯ 1
5
14 18
12 15
15 20
20 30
5 14
μμ μΆλ ₯ 1
2
import java.util.*;
class Time implements Comparable<Time>{
public int time;
public char state;
Time(int time, char state){
this.time = time;
this.state = state;
}
@Override
public int compareTo(Time o){
if(this.time == o.time){
return this.state - o.state;
}else{
return this.time - o.time;
}
}
}
public class Main {
public int solution(ArrayList<Time> time) {
int result = 0;
int tmp = 0;
for(int i=0; i<time.size(); i++){
if(time.get(i).state == 'e'){
tmp --;
}else{
tmp ++;
}
if(result<tmp){
result=tmp;
}
}
return result;
}
public static void main(String[] args) {
Main main = new Main();
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
ArrayList<Time> time = new ArrayList<>();
for(int i=0; i<n; i++){
Time tmp = new Time(kb.nextInt(), 's');
time.add(tmp);
tmp = new Time(kb.nextInt(), 'e');
time.add(tmp);
}
Collections.sort(time);
System.out.println(main.solution(time));
}
}
'κ°λ° > μκ³ λ¦¬μ¦ λ¬Έμ νμ΄ JAVA' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[νλ‘κ·Έλλ¨Έμ€/JAVA] κΈ°μ§κ΅ μ€μΉ (0) | 2022.02.17 |
---|---|
[JAVA/μ½λ©ν μ€νΈ] μ΅λ μμ μ€μΌμ₯΄(PriorityQueue μμ©λ¬Έμ ) (0) | 2022.02.15 |
[JAVA/μ½λ©ν μ€νΈ] μ¨λ¦ μ μ(Greedy Algorithm) (0) | 2022.02.12 |
[JAVA/μ½λ©ν μ€νΈ] μ‘°ν©μ κ²½μ°μ(λ©λͺ¨μ΄μ μ΄μ ) (0) | 2022.02.10 |
[JAVA/μ½λ©ν μ€νΈ] μμ΄κ΅¬νκΈ° (0) | 2022.02.08 |