Submission #1127799

#TimeUsernameProblemLanguageResultExecution timeMemory
1127799Oz121Rabbit Carrot (LMIO19_triusis)Java
0 / 100
125 ms12508 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 = 1;j<i+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] = -1; else dp[j] = dp[j-1]+jump; } } if (dp[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...