This answer quotes ChatGPT
According to the error message index-1 out of bounds for length 100010, it is likely that access to the array went out of bounds because the array Index had a negative value. Based on the for loop in the code, we can see that the index variable i of the loop is decreasing, not increasing. This means that in the loop, the value of i decreases until it is less than 0, resulting in a negative array index, which triggers an array out-of-bounds error.
Therefore, to fix this error, simply change the decrement operation in the for loop to an increment operation. Specifically, the code for(int i = 0; i < n; i--){for(int i = 0; i < n; i++){will do.
Here is an example of the corrected code:
import java.util.*;
import java.io.*;
public class Main{
static int N = 100010;
static int n,m;
static int skill[] = new int[N];
static int minus[] = new int[N];
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
long cnt = 0;
for(int i = 0; i < n; i++){
skill[i] = sc.nextInt();
minus[i] = sc.nextInt();
cnt += (skill[i] - 1) / minus[i] + 1;
}
m = (int)Math.min((long)m, cnt);
int l = 0, r = (int)1e6, mid = 0;
while(l < r){
mid = l + r + 1 >> 1;
if(check(mid)) l = mid;
else r = mid - 1;
}
}
// 根据题目描述写出 check 函数的代码
public static boolean check(int mid){
// TODO: 实现 check 函数
return true;
}
}