Advertisement
Vladkoheca

sumOfMins.java

Dec 15th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | Source Code | 0 0
  1. import java.util.*;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.  
  6.         int n = sc.nextInt();
  7.         int[] array = new int[n];
  8.         int sum = 0;
  9.  
  10.         for (int i = 0; i < n; i++) {
  11.             array[i] = sc.nextInt();
  12.         }
  13.  
  14.         for (int i = 0; i < n; i++) {
  15.             for (int j = i + 1; j < n; j++) {
  16.                 sum += Math.min(array[i], array[j]);
  17.             }
  18.         }
  19.         System.out.println(sum);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement