Submission #1127801

#TimeUsernameProblemLanguageResultExecution timeMemory
1127801Oz121Rabbit Carrot (LMIO19_triusis)Java
0 / 100
134 ms12376 KiB
import java.io.*; import java.util.*; public class triusis { public static int MIN = (-1)*((int) 2E9); 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, MIN); dp[0] = arr[0]; for (int i = 1;i<num;i++) { for (int j = i;j>=1;j--) { if (dp[j]>=arr[i]-jump) { dp[j] = arr[i]; dp[j] = Math.max(dp[j], dp[j-1]+jump); } else { if (dp[j-1]==-1) dp[j] = MIN; else dp[j] = dp[j-1]+jump; } } if (dp[0]>=arr[i]-jump) dp[0] = arr[i]; else dp[0] = MIN; } int ans = num; for (int i = num;i>=0;i--) { if (dp[i]>=0) 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...