Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- public class Homework {
- static int[] sortiraj(int a[])
- {
- boolean sortirana = false;
- while (!sortirana)
- {
- sortirana = true;
- for (int i = 0; i < a.length-1; i++)
- {
- if (a[i] > a[i+1])
- {
- sortirana = false;
- int temp = a[i];
- a[i] = a[i+1];
- a[i+1] = temp;
- }
- }
- }
- return a;
- }
- static int minBrojKazneni(int a[]) {
- int casoviPominato = 0;
- int vkupnoKazneni = 0;
- int sortirana[] = sortiraj(a);
- for (int i = 0; i < sortirana.length; i++)
- {
- casoviPominato += sortirana[i];
- vkupnoKazneni += casoviPominato;
- //System.out.printf("%d - %d kazneni, %d\n", sortirana[i], casoviPominato, vkupnoKazneni);
- }
- return vkupnoKazneni;
- }
- 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