2109번: 순회강연
한 저명한 학자에게 n(0 ≤ n ≤ 10,000)개의 대학에서 강연 요청을 해 왔다. 각 대학에서는 d(1 ≤ d ≤ 10,000)일 안에 와서 강연을 해 주면 p(1 ≤ p ≤ 10,000)만큼의 강연료를 지불하겠다고 알려왔다.
www.acmicpc.net
import java.util.*;
public class Main {
public static void main(String[] args) {
int n;
int max=0;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
ArrayList<Point> arr=new ArrayList<>();
for(int i=0;i<n;i++) {
int p=sc.nextInt(); int d=sc.nextInt();
arr.add(new Point(p,d));
max=Math.max(max, d);
}
Collections.sort(arr, new Comparator<Point>() {
@Override
public int compare(Point o1, Point o2) {
if(o1.p==o2.p) return o1.d-o2.p;
else return o2.p-o1.p;
}
});
int[] dd=new int[max+1];
for(int i=0;i<n;i++) {
int p=arr.get(i).p;
int d=arr.get(i).d;
while(d>0 && dd[d]!=0) {
d--;
}
if(d==0) continue;
else dd[d]=p;
}
int answer=0;
for(int i=1;i<=max;i++) answer+=dd[i];
System.out.println(answer);
}
static class Point{
int p;
int d;
public Point(int p, int d) {
this.p=p;
this.d=d;
}
}
}
'코테 공부' 카테고리의 다른 글
[SQL]오랜 기간 보호한 동물, 있었는데요 없었습니다. (프로그래머스)☆☆☆☆ (0) | 2022.10.18 |
---|---|
수열의 점수(백준 2036번), 자바(ArrayList 정렬하기) (0) | 2022.07.12 |
예산(백준 1512번),자바 (0) | 2022.07.06 |
맥주 마시면서 걸어가기(백준 9205번), 자바(☆☆) (0) | 2022.07.02 |
[DP]점프 점프(백준 11060번), 자바 (0) | 2022.06.29 |