BetinaUKTC

HW Mihaylov

Mar 17th, 2020
218
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 main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         int n = scan.nextInt();
  8.         int PreviousSum = 0;
  9.         int CurrentSum = 0;
  10.         int diff = 0;
  11.         for (int i = 1; i <= n; i++) {
  12.             if (i == 1) {
  13.                 int num1 = scan.nextInt();
  14.                 int num2 = scan.nextInt();
  15.                 PreviousSum = num1 + num2;
  16.             } else {
  17.                 int num1 = scan.nextInt();
  18.                 int num2 = scan.nextInt();
  19.                 CurrentSum = num1 + num2;
  20.                 if (Math.abs(CurrentSum - PreviousSum) > diff) {
  21.                     diff = Math.abs(CurrentSum - PreviousSum);
  22.                 }
  23.                 PreviousSum = CurrentSum;
  24.             }
  25.         }
  26.         if (diff != 0) {
  27.             System.out.println("No, maxdiff=" + diff);
  28.         } else {
  29.             System.out.println("Yes, value=" + PreviousSum);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment