Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class p12_Equal_Pairs {
  6.     public static void main(String[] args) {
  7.         Scanner console = new Scanner(System.in);
  8.         Integer n = console.nextInt();
  9.  
  10.         Integer currentSum = 0;
  11.         Integer previousSum = 0;
  12.         Integer diff = 0;
  13.         Integer maxDiff = 0;
  14.         for (int i = 0; i < n; i++) {
  15.             previousSum = currentSum;
  16.             currentSum = 0;
  17.             currentSum += console.nextInt();
  18.             currentSum += console.nextInt();
  19.             if (i != 0) {
  20.                 diff = Math.abs(currentSum - previousSum);
  21.                 if (diff != 0 && diff > maxDiff) {
  22.                     maxDiff = diff;
  23.                 }
  24.             }
  25.         }
  26.         if (previousSum == currentSum || n == 1) {
  27.             System.out.printf("Yes, value=%d", currentSum);
  28.  
  29.         } else {
  30.             System.out.printf("No, maxdiff=%d", maxDiff);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement