为什么代码在eclipse上运行没问题,但在OJ系统上出现运行错误啊?
help ~
import java.util.*;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); //8
int S = sc.nextInt(); //3
int[] a= new int[N+1]; //8
for (int i = 1; i <= N; i++) {
a[i]=sc.nextInt();
}
for (int j = N; j >= 2; j-=2 ) {
if (iscut(a,j,S)) { //j 8 , s 3
System.out.println(j);
break;
}
}
}
private static boolean iscut(int[] a, int x ,int s) {
int left=1;
int right=x; //8
int leftcount=0;
int rightcount=0;
while (left<right) {
leftcount+=a[left];
rightcount+=a[right];
left++;
right--;
}
return leftcount<=s && rightcount<=s;
}
}