Advertisement
bakhridinova

Untitled

Jul 3rd, 2023
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class Contest27393 {
  7.     public static void main(String[] args) {
  8.        new Contest27393().problemF();
  9.     }
  10.  
  11.     private Scanner scanner;
  12.  
  13.     public void problemF() {
  14.         scanner = new Scanner(System.in);
  15.         int a1 = scanner.nextInt();
  16.         int b1 = scanner.nextInt();
  17.         int a2 = scanner.nextInt();
  18.         int b2 = scanner.nextInt();
  19.  
  20.         List<Pair> pairs = new ArrayList<>(List.of(
  21.                 new Pair(Math.max(a1, a2), b1 + b2),
  22.                 new Pair(Math.max(a2, b1), a1 + b2),
  23.                 new Pair(Math.max(a1, b2), a2 + b1),
  24.                 new Pair(Math.max(b1, b2), a1 + a2)
  25.         ));
  26.  
  27.         Collections.sort(pairs);
  28.         Pair pair = pairs.get(0);
  29.         System.out.println(pair.getA() + " " + pair.getB());
  30.     }
  31.  
  32.     private static class Pair implements Comparable<Pair> {
  33.         private final int a;
  34.         private final int b;
  35.  
  36.         public Pair(int a, int b) {
  37.             this.a = a;
  38.             this.b = b;
  39.         }
  40.  
  41.         public int getA() {
  42.             return a;
  43.         }
  44.  
  45.         public int getB() {
  46.             return b;
  47.         }
  48.  
  49.         @Override
  50.         public int compareTo(Pair pair) {
  51.             return Integer.compare(this.getA() * this.getB(), pair.getA() * pair.getB());
  52.         }
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement