1 import java.util.*; 2 3 public class Main { 4 public static void main(String[] args) { 5 Scanner scanner=new Scanner(System.in); 6 int n=scanner.nextInt(); 7 long x=scanner.nextLong(); 8 //前缀和 9 long[]arr=new long[n+1]; 10 arr[0]=0; 11 for(int i=1;i<=n-1;i++) { 12 arr[i]=scanner.nextLong()+arr[i]; 13 } 14 arr[n]=arr[n-1]+9999999999L; 15 int l=0; 16 int sum=0; 17 for(int i=1;i<=n;i++) { 18 if(arr[i]-arr[l]>=2L*x) { 19 sum=Math.max(sum, i-l); 20 l+=1; 21 } 22 } 23 System.out.print(sum); 24 } 25 }
标签:二分,arr,scanner,int,sum,青蛙,long,前缀 From: https://www.cnblogs.com/saucerdish/p/18094263