Advertisement
Filip_Markoski

2.Lab2.3 Faculty (Solved)

Oct 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.util.Arrays;
  4.  
  5. public class Homework {
  6.    
  7.     static int minBrojKazneni(int a[]) {
  8.         /* So all assignments are given at the same time */
  9.         int sum = 0;
  10.         /* By starting with the smallest we can be sure that the student avoids the most penalty points */
  11.         Arrays.sort(a);
  12.         /* We calculate the penalty points by the hours passed */
  13.         int done[] = new int[a.length];
  14.         done[0] = a[0];
  15.         /* [1][2][2][3][3][3] => 1 + 3 + 6 = 10 */
  16.         for (int i = 1; i < a.length; i++) {
  17.             done[i] = done[i-1] + a[i];
  18.         }
  19.         for (int i = 0; i < done.length; i++) {
  20.             sum += done[i];
  21.         }
  22.         return sum;
  23.     }
  24.    
  25.     public static void main(String[] args) throws Exception {
  26.         int i;
  27.        
  28.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  29.         int N = Integer.parseInt(br.readLine());
  30.         int a[] = new int[N];
  31.        
  32.         for (i=0;i<N;i++)
  33.             a[i] = Integer.parseInt(br.readLine());
  34.        
  35.         int rez = minBrojKazneni(a);
  36.        
  37.         System.out.println(rez);
  38.        
  39.         br.close();
  40.     }
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement