Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EqualPairs {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num = Integer.parseInt(scanner.nextLine());
- int sum = 0;
- int maxDiff = 0;
- int lastSum = 0;
- int counter = 1;
- for (int i = 1; i <= num; i++) {
- int n1 = Integer.parseInt(scanner.nextLine());
- int n2 = Integer.parseInt(scanner.nextLine());
- sum = n1 + n2;
- if (sum == lastSum){
- counter++;
- }
- if (i > 1){
- int currentDiff =Math.abs( lastSum - sum);
- if (currentDiff>maxDiff){
- maxDiff = currentDiff;
- }
- }
- lastSum = sum;
- }if (counter == num){
- System.out.printf("Yes, value=%d",sum);
- }else{
- System.out.printf("No, maxdiff=%d", maxDiff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement