https://www.acmicpc.net/problem/14501
import java.util.*; public class 퇴사 { int[] chk; int max =0 ; public static void main(String[] args) { int n; 퇴사 app = new 퇴사(); Scanner sc = new Scanner(System.in); n = sc.nextInt(); app.chk = new int[n]; int [] t = new int[n]; int [] p = new int[n]; int [] profit = new int[n]; for(int i=0;i<n;i++) { t[i] = sc.nextInt(); p[i] = sc.nextInt(); profit[i] = p[i]; } for(int i=1;i<n;i++) { for(int j=0;j<i;j++) { if( i-j >= t[j] ) { profit[i] = Math.max(p[i]+profit[j], profit[i]); } } } int max = 0; for(int i=0;i<n;i++) { if(i+t[i]<=n) { if(max<profit[i]) { max = profit[i]; } } } System.out.println(max); } }
'IT > 알고리즘' 카테고리의 다른 글
프로그래머스 lv2 프린터 (0) | 2019.11.19 |
---|---|
프로그래머스 lv2 다리를 지나는 트럭 (0) | 2019.11.16 |
프로그래머스 스킬트리(java) (0) | 2019.11.11 |
프로그래머스 쇠막대기 문제(java) (0) | 2019.11.11 |
프로그래머스 Lv2 주식가격 (0) | 2019.10.28 |