fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int[] arr = {0, 1, 2, 3, 4, 5, 6};
  14. int m = 5;
  15. int n = arr.length;
  16.  
  17. int[] dp = new int[n];
  18.  
  19. dp[0] = 1;
  20.  
  21. int maxPart = 0;
  22. for(int i = 1; i < n; i++){
  23.  
  24. int sum = arr[i];
  25. int j = i;
  26. while(j >= 1 && sum <= m){
  27. dp[i] += dp[j-1];
  28. j--;
  29. sum += arr[j];
  30. }
  31. maxPart = Math.max(maxPart, dp[i]);
  32. }
  33.  
  34. System.out.print(maxPart);
  35. }
  36. }
Success #stdin #stdout 0.08s 54616KB
stdin
Standard input is empty
stdout
3