Table of Contents

Video SolutionExplanation

Official Analysis (C++)

Video Solution

By Jeffrey Meng

Video Solution Code

Explanation

Notice that the two smallest values in the sorted list will be AA and BB, and the largest value will always equal to A+B+CA + B + C. By subtracting AA and BB from A+B+CA + B + C, we obtain the value of CC.

Python

nums = sorted([int(x) for x in input().split()])
a, b = nums[0], nums[1]
c = nums[6] - a - b
print(f"{a} {b} {c}")

C++

#include <bits/stdc++.h>
using namespace std;
int main() {
int nums[7];
for (int i = 0; i < 7; i++) { cin >> nums[i]; }
sort(nums, nums + 7);
int a = nums[0], b = nums[1];
int c = nums[6] - a - b;
cout << a << ' ' << b << ' ' << c << '\n';
}

Java

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!