来个骚的 import java.util.Arrays; import java.util.Scanner; public class Main {         public static void main(String[] args) {                           //O(nlogn)                  Scanner scanner=new Scanner(System.in);         int n=scanner.nextInt();                  int a[]=new int[n];                  for (int i = 0; i < a.length; i++) {             a[i]=scanner.nextInt();         }                  int m=scanner.nextInt();         int q[]=new int[m];                           for (int i = 0; i < q.length; i++) {             q[i]=scanner.nextInt();         }                                    scanner.close();                                    int count[]=new int[n];         count[0]=a[0];                  for (int i = 1; i < count.length; i++) {             count[i]=count[i-1]+a[i];         }                                             for (int i = 0; i < q.length; i++) {                          int s=Arrays.binarySearch(count, q[i]);                                       if(s>0) {                 System.out.println(s+1);             }else {                                  System.out.println(Math.abs(s));             }                                                             }                                                                             }      }
点赞 评论

相关推荐

Pandaileee:校友加油我现在也只有一个保底太难了
点赞 评论 收藏
分享
牛客网
牛客企业服务