제출 #1127805

#제출 시각아이디문제언어결과실행 시간메모리
1127805Oz121Rabbit Carrot (LMIO19_triusis)Java
63 / 100
1099 ms32668 KiB
import java.io.*; import java.util.*; public class triusis { public static void main(String[] args) throws IOException { BufferedReader scan = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer l1 = new StringTokenizer(scan.readLine()); int num = Integer.parseInt(l1.nextToken()); int jump = Integer.parseInt(l1.nextToken()); int[] arr = new int[num]; for (int i = 0;i<num;i++) { StringTokenizer st = new StringTokenizer(scan.readLine()); arr[i] = Integer.parseInt(st.nextToken()); } int[] dp = new int[num+1]; Arrays.fill(dp, -1); dp[0] = 0; for (int i = 0;i<num;i++) { for (int j = i+1;j>=1;j--) { if (dp[j]>=Math.max(0,arr[i]-jump)) { dp[j] = arr[i]; if (dp[j-1]!=-1) dp[j] = Math.max(dp[j], dp[j-1]+jump); } else { if (dp[j-1]==-1) dp[j] = -1; else dp[j] = dp[j-1]+jump; } } if (dp[0]>=Math.max(0,arr[i]-jump)) dp[0] = arr[i]; else dp[0] = -1; } int ans = num; for (int i = num;i>=0;i--) { if (dp[i]!=-1) ans = i; } System.out.println(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...