-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforce978C.java
More file actions
59 lines (35 loc) · 1.4 KB
/
Copy pathCodeforce978C.java
File metadata and controls
59 lines (35 loc) · 1.4 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
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class Codeforce978C {
public static void main(String[] args)throws Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokn = new StringTokenizer(input.readLine());
Long n = Long.parseLong(tokn.nextToken());
Long m = Long.parseLong(tokn.nextToken());
tokn = new StringTokenizer(input.readLine());
ArrayList<Long> value = new ArrayList<>();
long previous = 0;
for (int i = 0; i < n; i++) {
previous = Long.parseLong(tokn.nextToken()) + previous;
value.add(previous);
}
tokn = new StringTokenizer(input.readLine());
StringBuilder out = new StringBuilder();
for (int i = 0; i < m; i++) {
long position = Long.parseLong(tokn.nextToken());
int x = Collections.binarySearch(value, position);
if (x <= -1 ){
x = x * -1 - 1;
}
if (x == 0){
out.append(x + 1).append(" ").append(position).append("\n");
}else{
out.append(x + 1).append(" ").append(position - value.get(x - 1)).append("\n");
}
}
System.out.println(out);
}
}