class Main07Test { public int help(int[] arr, int n, int target) { int left = 0, right = 0; int windowSum = arr[0]; int maxLen = 0; while (right < n - 1) { // 扩窗 // if (arr[right] > target) break; // 剪枝 right++; // 一开始会加一 windowSum += arr[right]; // 缩窗 while (left <= right && windowSum > target) { windowSum -= arr[left]; left++; } // 符合条件 if (left <= right && windowSum == target) { maxLen = Math.max(maxLen, right - left + 1); windowSum -= arr[left]; left++; } } return maxLen; } } public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] strings = br.readLine().split(" "); int n = Integer.parseInt(strings[0]); int target = Integer.parseInt(strings[1]); int[] arr = new int[n]; // 每次读行 String[] strs = br.readLine().split(" "); for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(strs[i]); } Main07Test test = new Main07Test(); int help = test.help(arr, n, target); System.out.println(help); } }