Advertisement
Guest User

Untitled

a guest
Feb 28th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.72 KB | None | 0 0
  1. package aer396;
  2.  
  3. import java.util.*;
  4.  
  5.  
  6. /**
  7.  *
  8.  * @author victor
  9.  */
  10. public class AER396 {
  11.  
  12.     static class Instrumento implements Comparable<Instrumento> {
  13.         short musicos;
  14.         short partituras;
  15.        
  16.         public Instrumento(short musicos) {
  17.             this.musicos = musicos;
  18.             this.partituras = 1;
  19.         }
  20.        
  21.         short max() {
  22.             return (short)Math.ceil(musicos / (double)partituras);
  23.         }
  24.        
  25.         Instrumento inc() {
  26.             partituras++;
  27.             return this;
  28.         }
  29.  
  30.         @Override
  31.         public int compareTo(Instrumento arg0) {
  32.             return arg0.max() - this.max();
  33.         }
  34.        
  35.         @Override
  36.         public String toString() {
  37.             return String.format("%d/%d(%d)", musicos, partituras, max());
  38.         }
  39.     }
  40.    
  41.     static Scanner in = new Scanner(System.in);
  42.  
  43.    
  44.    
  45.    
  46.     public static void caso() {
  47.         int nPartituras = in.nextInt();
  48.         int nInstrumentos = in.nextInt();
  49.         PriorityQueue<Instrumento> instrumentos = new PriorityQueue<Instrumento>();
  50.         for (int i = 0; i < nInstrumentos; i++) {
  51.             instrumentos.add(new Instrumento(in.nextShort()));
  52.         }
  53.         int sobran = nPartituras - nInstrumentos;
  54.         for (int i = 0; i < sobran; i++) {
  55.             Instrumento sobre = instrumentos.poll();
  56.             // System.err.println(sobre.musicos);
  57.             sobre.inc();
  58.             instrumentos.add(sobre);
  59.         }
  60.         Instrumento sobre = instrumentos.poll();
  61.         System.out.println(sobre.max());
  62.     }
  63.  
  64.     public static void main(String[] args) {
  65.         while (in.hasNext()) {
  66.             caso();
  67.         }
  68.     }
  69.    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement