Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- public class Homework {
- static int minBrojKazneni(int a[]) {
- /* So all assignments are given at the same time */
- int sum = 0;
- /* By starting with the smallest we can be sure that the student avoids the most penalty points */
- Arrays.sort(a);
- /* We calculate the penalty points by the hours passed */
- int done[] = new int[a.length];
- done[0] = a[0];
- /* [1][2][2][3][3][3] => 1 + 3 + 6 = 10 */
- for (int i = 1; i < a.length; i++) {
- done[i] = done[i-1] + a[i];
- }
- for (int i = 0; i < done.length; i++) {
- sum += done[i];
- }
- return sum;
- }
- public static void main(String[] args) throws Exception {
- int i;
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int N = Integer.parseInt(br.readLine());
- int a[] = new int[N];
- for (i=0;i<N;i++)
- a[i] = Integer.parseInt(br.readLine());
- int rez = minBrojKazneni(a);
- System.out.println(rez);
- br.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement