Advertisement
Dev-san

Untitled

Nov 2nd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3.  
  4. public class Homework {
  5.    
  6.     static int[] sortiraj(int a[])
  7.     {
  8.         boolean sortirana = false;
  9.         while (!sortirana)
  10.         {
  11.             sortirana = true;
  12.             for (int i = 0; i < a.length-1; i++)
  13.             {
  14.                 if (a[i] > a[i+1])
  15.                 {
  16.                     sortirana = false;
  17.                     int temp = a[i];
  18.                     a[i] = a[i+1];
  19.                     a[i+1] = temp;
  20.                 }
  21.             }
  22.         }
  23.         return a;
  24.     }
  25.    
  26.     static int minBrojKazneni(int a[]) {
  27.         int casoviPominato = 0;
  28.         int vkupnoKazneni = 0;
  29.         int sortirana[] = sortiraj(a);
  30.        
  31.         for (int i = 0; i < sortirana.length; i++)
  32.         {
  33.             casoviPominato += sortirana[i];
  34.             vkupnoKazneni += casoviPominato;
  35.             //System.out.printf("%d - %d kazneni, %d\n", sortirana[i], casoviPominato, vkupnoKazneni);
  36.         }
  37.        
  38.         return vkupnoKazneni;
  39.     }
  40.    
  41.     public static void main(String[] args) throws Exception {
  42.         int i;
  43.        
  44.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  45.         int N = Integer.parseInt(br.readLine());
  46.         int a[] = new int[N];
  47.        
  48.         for (i=0;i<N;i++)
  49.             a[i] = Integer.parseInt(br.readLine());
  50.        
  51.         int rez = minBrojKazneni(a);
  52.        
  53.         System.out.println(rez);
  54.        
  55.         br.close();
  56.     }
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement