Cover Them All!

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int tc = scan.nextInt();
while(tc!=0) {
int nos = scan.nextInt();
int[] x = new int[nos];
for(int i=0;i<nos;i++) {
x[i] = scan.nextInt();

  }
  int[] y = new int[nos];
  for(int i=0;i<nos;i++) {
	 y[i] = scan.nextInt();
	  
  }
  System.out.println(Work(x,y));
  
  tc--;

}

}

private static int  Work(int[] x, int[] y) {
	int ans =0;
	for(int i=0;i<x.length;i++) {
		for(int j=i;j<y.length;j++) {
			ans +=(x[i]-x[j])*(Math.max(y[i], y[j]));
		}
	}
	return Math.abs(ans);
}

}

// ans come wrong on hackerblock but true come on my Ids

please share the hackerblocks link to this question as you have tagged the wrong q in your doubt

https://hack.codingblocks.com/app/practice/3/715/problem

Scanner scan = new Scanner(System.in);
int tc = scan.nextInt();
while(tc!=0) {
int nos = scan.nextInt();
int[] x = new int[nos];
for(int i=0;i<nos;i++) {
x[i] = scan.nextInt();

  }
  int[] y = new int[nos];
  for(int i=0;i<nos;i++) {
	 y[i] = scan.nextInt();
	  
  }
  System.out.println(Work(x,y));
  
  tc--;

}

}

private static int  Work(int[] x, int[] y) {
	int ans =0;
	for(int i=0;i<x.length;i++) {
		for(int j=i;j<y.length;j++) {
			ans =(ans%mod+(Math.abs(x[i]-x[j])%mod*Math.max(y[i], y[j])%mod))%mod;
		}
	}

	return Math.abs(ans);
}

}
// Its not pass any testcase