Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class E10HalfSumElement {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int sum = 0;
- int maxNum = Integer.MIN_VALUE;
- for (int i = 0; i < n; i++) {
- int num = Integer.parseInt(scanner.nextLine());
- sum += num;
- if (num > maxNum) {
- maxNum = num;
- }
- }
- if (sum - maxNum == maxNum) {
- System.out.printf("Yes%nSum = %d%n", maxNum);
- } else {
- System.out.printf("No%nDiff = %d%n", Math.abs(maxNum - (sum - maxNum)));
- }
- }
- }
Add Comment
Please, Sign In to add comment