sábado, 11 de junio de 2011

1025. Democracy in Danger

Background
In one of the countries of Caribbean basin all decisions were accepted by the simple majority of votes at the general meeting of citizens (fortunately, there were no lots of them). One of the local parties, aspiring to come to power as lawfully as possible, got its way in putting into effect some reform of the election system. The main argument was that the population of the island recently had increased and it was to longer easy to hold general meetings.
The essence of the reform is as follows. From the moment of its coming into effect all the citizens were divided into K (may be not equal) groups. Votes on every question were to be held then in each group, moreover, the group was said to vote “for” if more than half of the group had voted “for”, otherwise it was said to vote “against”. After the voting in each group a number of group that had voted “for” and “against” was calculated. The answer to the question was positive if the number of groups that had voted “for” was greater than the half of the general number of groups.
At first the inhabitants of the island accepted this system with pleasure. But when the first delights dispersed, some negative properties became obvious. It appeared that supporters of the party, that had introduced this system, could influence upon formation of groups of voters. Due to this they had an opportunity to put into effect some decisions without a majority of voters “for” it.
Let’s consider three groups of voters, containing 5, 5 and 7 persons, respectively. Then it is enough for the party to have only three supporters in each of the first two groups. So it would be able to put into effect a decision with the help of only six votes “for” instead of nine, that would be necessary in the case of general votes.
Problem
You are to write a program, which would determine according to the given partition of the electors the minimal number of supporters of the party, sufficient for putting into effect of any decision, with some distribution of those supporters among the groups.

Input
In the first line an only odd integer K — a quantity of groups — is written (1 ≤ K ≤ 101). In the second line there are written K odd integers, separated with a space. Those numbers define a number of voters in each group. The population of the island does not exceeds 9999 persons.

Output
You should write a minimal quantity of supporters of the party, that can put into effect any decision.

Sample
Input:
3
5 7 5


Output
6

http://acm.timus.ru/problem.aspx?space=1&num=1025



import java.util.Arrays;

public class Problema1025 
{
   public static void main( String args[] ) throws Exception
   {
      int numGrupos = sig();System.in.read();
  
      int[] grupos = new int[ numGrupos ];
  
      // Almacenamos el numero de integrantes de cada grupo
      for( int i = 0; i < numGrupos; i ++ )
         grupos[ i ] = sig();
  
      // Ordenamos los grupos, para que sea mas facil hallar la
      // cantidad minima de votos
      Arrays.sort( grupos );
  
      int votosMinimo = 0;
  
      // Si son n grupos, el minimo numero de grupos que deben de 
      // estar de acuerdo es la mitad mas uno.
      int gruposMinimo = ( numGrupos + 1 ) / 2; 
   
      // La cantidad minima de cada grupo que debe estar de acuerdo es
      // la mitad de los integrantes de dicho grupo mas uno.
      // Por lo tanto para que el total de votos sea lo menor posible, 
      // buscamos en los grupos que tengan menos integrantes.
      for( int i = 0; i < gruposMinimo; i ++ )
         votosMinimo = votosMinimo + ( grupos[ i ] + 1 )/2;
  
      System.out.println( votosMinimo );
   }
 
   public static int sig() throws Exception
   {
      int val = System.in.read() - 48;
      int car = System.in.read();
  
      while( car > 47 && car < 58 )
      {
         val = 10 * val + car - 48;
         car = System.in.read();
      }
  
      return val;
   }
}

No hay comentarios:

Publicar un comentario