public static int MaxValue(int m, ArrayList<Integer> list) { int start = 0; int index = start; for (; index < m; index++) { if (index >= list.size()) { break; } if (list.get(index) > 0) { m += list.get(index); m -= (index - start); start = index; } } if (index >= list.size()) { return m; } else { return -1; } }不知道对不对,没有oj能测试了