-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetters.java
More file actions
44 lines (39 loc) · 1.47 KB
/
Letters.java
File metadata and controls
44 lines (39 loc) · 1.47 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
/**
* Created by MalhotR1 on 05/13/2018.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Letters {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
String[] in = br.readLine().trim().split(" ");
int a = Integer.parseInt(in[0]);
int b = Integer.parseInt(in[1]);
in = br.readLine().split(" ");
long[] dorm = new long[in.length];
long sum = 0;
for (int i = 0; i < in.length; i++) {
dorm[i] = Long.parseLong(in[i]) + sum;
sum = dorm[i];
}
in = br.readLine().trim().split(" ");
long[] arr = new long[in.length];
for (int i = 0; i < in.length; i++) {
arr[i] = Long.parseLong(in[i]);
}
int next = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] <= dorm[next]) {
long r = arr[i];
if (next != 0) r = r - dorm[next - 1];
System.out.println((next + 1) + " " + r);
} else {
while (next < dorm.length && dorm[next] < arr[i]) next++;
long r = arr[i] - dorm[next - 1];
System.out.println((next + 1) + " " + r);
}
}
}
}
}