-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT2.java
More file actions
46 lines (43 loc) · 1.03 KB
/
T2.java
File metadata and controls
46 lines (43 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package neteasy;
import java.util.Scanner;
/**
* @Author:Aliyang
* @Data: Created in 下午12:57 18-8-11
**/
public class T2 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n;
n=sc.nextInt();
int[] a=new int[n];
int sum=0;
for (int i=0;i<n;i++){
sum+=sc.nextInt();
a[i]=sum;
}
int m;
m=sc.nextInt();
int[] q=new int[m];
for (int i=0;i<m;i++)
q[i]=sc.nextInt();
for (int i=0;i<m;i++){
int query=q[i];
int l=0;
int r=n-1;
while (l<=r){
int mid=(l+r)/2;
if (query==a[mid]){
System.out.println(mid+1);
break;
}else if (query>a[mid]){
l=mid+1;
}else {
r=mid-1;
}
}
if (l>r){
System.out.println(l+1);
}
}
}
}