Untitled

mail@pastecode.io avatar
unknown
plain_text
11 days ago
563 B
4
Indexable
Never
  public static boolean canAchieveTarget(int n, long c, int d, int[] arr, int k) {
        long[] skillPoints = new long[d + 1];
        for (int i = 0; i < n; i++) {
            // Skip if the exercise can't be used within the day limit
            if (arr[i] <= 0) continue;
            for (int j = d; j >= 1; j--) {
                for (int t = j - 1; t >= Math.max(0, j - k - 1); t--) {
                    skillPoints[j] = Math.max(skillPoints[j], skillPoints[t] + arr[i]);
                }
            }
        }
        return skillPoints[d] >= c;
    }
Leave a Comment