Advertisement
damesova

Equal Pairs [Mimi][PB]

May 23rd, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EqualPairs {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         int sum1 = 0;
  9.         int sum2 = 0;
  10.         int diff = 0;
  11.  
  12.         for (int i = 1; i <= n; i++) {
  13.             int num1 = Integer.parseInt(scanner.nextLine());
  14.             int num2 = Integer.parseInt(scanner.nextLine());
  15.  
  16.             if (i % 2 == 0) {
  17.                 sum2 = num1 + num2;
  18.             } else {
  19.                 sum1 = num1 + num2;
  20.             }
  21.             if (i > 1 && Math.abs(sum2 - sum1) > diff) {
  22.                 diff = Math.abs(sum2 - sum1);
  23.             }
  24.  
  25.         }
  26.  
  27.         if (diff == 0) {
  28.             System.out.println("Yes, value=" + sum1);
  29.         } else {
  30.             System.out.println("No, maxdiff=" + diff);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement