Video Solution
By Jeffrey Meng
Video Solution Code
Explanation
Notice that the two smallest values in the sorted list will be and , and the largest value will always equal to . By subtracting and from , we obtain the value of .
import java.io.*;import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int nums[] = new int[7];for (int i = 0; i < 7; i++) { nums[i] = sc.nextInt(); }Arrays.sort(nums);int a = nums[0], b = nums[1];int c = nums[6] - a - b;System.out.println(a + " " + b + " " + c);}}
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!