//踏前斩 public static long cost(int[] arr, int len) { long res = 0l; for (int i = len - 1; i >= 2; i--) { int cnt = Math.min(arr[i - 2], Math.min(arr[i - 1] / 2, arr[i] / 3)); res += (5l * cnt); arr[i - 2] -= cnt; arr[i - 1] -= (cnt << 1); arr[i] -= (cnt * 3); } for (int i = 0; i < len; i++) { res = res + arr[i]; } return res; }