Advertisement
CR7CR7

Equal Pairs

Apr 5th, 2023
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.   public static void main(String[] args) {
  5.     Scanner scanner = new Scanner(System.in);
  6.  
  7.     int count = scanner.nextInt();
  8.     int previousSum = scanner.nextInt() + scanner.nextInt();
  9.  
  10.     int maxDifference = 0;
  11.     for (int i = 1; i < count; i++) {
  12.       int currentSum = scanner.nextInt() + scanner.nextInt();
  13.       maxDifference = Math.max(maxDifference, Math.abs(previousSum - currentSum));
  14.       previousSum = currentSum;
  15.     }
  16.  
  17.     if (maxDifference == 0) {
  18.       System.out.println("Yes, value=" + previousSum);
  19.     } else {
  20.       System.out.println("No, maxdiff=" + maxDifference);
  21.     }
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement