Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aer396;
- import java.util.*;
- /**
- *
- * @author victor
- */
- public class AER396 {
- static class Instrumento implements Comparable<Instrumento> {
- short musicos;
- short partituras;
- public Instrumento(short musicos) {
- this.musicos = musicos;
- this.partituras = 1;
- }
- short max() {
- return (short)Math.ceil(musicos / (double)partituras);
- }
- Instrumento inc() {
- partituras++;
- return this;
- }
- @Override
- public int compareTo(Instrumento arg0) {
- return arg0.max() - this.max();
- }
- @Override
- public String toString() {
- return String.format("%d/%d(%d)", musicos, partituras, max());
- }
- }
- static Scanner in = new Scanner(System.in);
- public static void caso() {
- int nPartituras = in.nextInt();
- int nInstrumentos = in.nextInt();
- PriorityQueue<Instrumento> instrumentos = new PriorityQueue<Instrumento>();
- for (int i = 0; i < nInstrumentos; i++) {
- instrumentos.add(new Instrumento(in.nextShort()));
- }
- int sobran = nPartituras - nInstrumentos;
- for (int i = 0; i < sobran; i++) {
- Instrumento sobre = instrumentos.poll();
- // System.err.println(sobre.musicos);
- sobre.inc();
- instrumentos.add(sobre);
- }
- Instrumento sobre = instrumentos.poll();
- System.out.println(sobre.max());
- }
- public static void main(String[] args) {
- while (in.hasNext()) {
- caso();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement