Advertisement
Guest User

C4DELIMOSTNA4

a guest
Mar 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.lang.Math.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11.     public static void main (String[] args) throws java.lang.Exception
  12.     {
  13.         Scanner in=new Scanner(System.in);
  14.         PrintStream out=new PrintStream(System.out);
  15.         int n=in.nextInt();
  16.         int x1,x2;
  17.         int sum=0;
  18.         int d;
  19.         int delta=10001;
  20.         for(int i=0;i<n;i++){
  21.             x1=in.nextInt();
  22.             x2=in.nextInt();
  23.                 if(x1>x2){
  24.                     sum+=x1;
  25.                 }
  26.                 else{
  27.                     sum+=x2;
  28.                 }
  29.             d=Math.abs(x1-x2);
  30.                 if((d%4!=0) && (d<delta)){
  31.                     delta=d;
  32.                 }
  33.             }
  34.             if(sum%4==0){
  35.                 if(delta==10001){
  36.                     sum=0;
  37.                 }
  38.             else{
  39.                 sum=sum-delta;
  40.                 }
  41.             }
  42.             out.println(sum);
  43.             }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement