-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathletters.java
More file actions
35 lines (34 loc) · 906 Bytes
/
letters.java
File metadata and controls
35 lines (34 loc) · 906 Bytes
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
import java.io.*;
import java.util.*;
import java.lang.*;
public class letters{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int i,n,m;
n = sc.nextInt();
m = sc.nextInt();
long[] a = new long[n];
for(i=0;i<n;i++){
a[i] = sc.nextLong();
}
int x=1;
long suma=a[x-1];
long sumb = 0;
for(i=0;i<m;i++){
long b = sc.nextLong();
if(b<=suma){
System.out.println(x+" "+(b-sumb));
}else if(b>suma){
while(b>suma){
x++;
suma+=a[x-1];
if((x-2)>=0)
sumb+=a[x-2];
else
sumb+=0;
}
System.out.println(x+" "+(b-sumb));
}
}
}
}