-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiblioteca.java
More file actions
29 lines (29 loc) · 844 Bytes
/
Biblioteca.java
File metadata and controls
29 lines (29 loc) · 844 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
import java.util.*;
public class ECCPR{
public static void main(String []args){
int lim,n,nr,pag;
Scanner sc= new Scanner(System.in);
lim=sc.nextInt();
n=sc.nextInt();
ArrayList<Integer>list=new ArrayList<Integer>();
for(int i=0;i<n;i++){
nr=sc.nextInt();
pag=sc.nextInt();
for(int j=0;j<nr;j++){
list.add(pag);
}
}
int suma=0;
while(list.size()>0){
for(int i=0;i<list.size();){
if(list.get(i)+suma<=lim){
suma+=list.get(i);
System.out.print(list.get(i)+" ");
list.remove(i);
}else i++;
}
System.out.println();
suma=0;
}
}
}