-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoinsKefa.java
More file actions
45 lines (34 loc) · 999 Bytes
/
CoinsKefa.java
File metadata and controls
45 lines (34 loc) · 999 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
36
37
38
39
40
41
42
43
44
45
import java.util.*;
public class CoinsKefa {
public static void main(String[] args) {
int m, n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
int a[] = new int[n];
int p[] = new int[m];
for(int i =0;i<n;i++){
a[i] = sc.nextInt();
}
Arrays.sort(a);
for(int i =0;i<m;i++){
p[i] = sc.nextInt();
}
int x=0,k=0,start=0;
for(int i=0; i<m; i++){
if(start>=n){
System.out.println(-1+" "+-1);
}
else{
while(k<p[i] && start < n){
k = k + a[start];
start++;
x++;
}
System.out.println(x+" "+k);
x=0;
k=0;
}
}
}
}