Advertisement
EliPerfanova

Equal Pairs

Oct 19th, 2019
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 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.  
  7.         int num = Integer.parseInt(scanner.nextLine());
  8.         int sum = 0;
  9.         int maxDiff = 0;
  10.         int lastSum = 0;
  11.         int counter = 1;
  12.  
  13.         for (int i = 1; i <= num; i++) {
  14.             int n1 = Integer.parseInt(scanner.nextLine());
  15.             int n2 = Integer.parseInt(scanner.nextLine());
  16.  
  17.             sum = n1 + n2;
  18.             if (sum == lastSum){
  19.                 counter++;
  20.             }
  21.             if (i > 1){
  22.                 int currentDiff =Math.abs( lastSum - sum);
  23.                 if (currentDiff>maxDiff){
  24.                     maxDiff = currentDiff;
  25.  
  26.                 }
  27.             }
  28.             lastSum = sum;
  29.  
  30.  
  31.         }if (counter == num){
  32.             System.out.printf("Yes, value=%d",sum);
  33.  
  34.         }else{
  35.  
  36.             System.out.printf("No, maxdiff=%d", maxDiff);
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement