import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 int N = in.nextInt(); int k = in.nextInt(); int[] arr = new int[N+1]; arr[0] = 0; int res = 0; for (int i = 1; i <= N; i++) { arr[i] = in.nextInt(); if (arr[i] == k) { res = 1; } //用原来的数据,构造前缀和数组 arr[i] += arr[i-1]; } int l = 0, r = 1; while (r <= N) { int num = arr[r] - arr[l]; if (num == k) { res = Math.max(res,r - l); l++; }else if (num < k) { r++; }else { l++; } } System.out.print(res); } }