1- import java .util .*;
21import java .io .*;
2+ import java .util .*;
3+ import java .text .*;
4+ import java .math .*;
5+ import java .util .regex .*;
36
4- /*
5- * @author -- rajatgoyal715
6- */
7+ public class Solution {
78
8- public class CuttingBoards {
99 public static void main (String [] args ) throws IOException {
1010 Scanner sc = new Scanner (System .in );
1111 int t = sc .nextInt ();
12+ // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+ // int t = Integer.parseInt(br.readLine());
1214 StringBuilder sb = new StringBuilder ("" );
1315 while (t --!=0 ){
1416 int m = sc .nextInt ();
1517 int n = sc .nextInt ();
18+ // String s1[] = br.readLine().split(" ");
19+ // int m = Integer.parseInt(s1[0]);
20+ // int n = Integer.parseInt(s1[1]);
1621 long y [] = new long [m -1 ];
22+ // String s2[] = br.readLine().split(" ");
1723 for (int i =0 ;i <m -1 ;i ++){
1824 y [i ] = sc .nextLong ();
25+ // y[i] = Integer.parseInt(s2[i]);
1926 }
2027 long x [] = new long [n -1 ];
28+ // String s3[] = br.readLine().split(" ");
2129 for (int i =0 ;i <n -1 ;i ++){
2230 x [i ] = sc .nextLong ();
31+ // x[i] = Integer.parseInt(s3[i]);
2332 }
24- sb .append (cutBoard (m , n , y , x ) + "\n " );
33+ sb .append (cost (m , n , y , x ) + "\n " );
2534 }
2635 System .out .println (sb .toString ());
2736 }
2837
29- public static long cutBoard (int m , int n , long [] y , long [] x ){
38+ public static long cost (int m , int n , long [] y , long [] x ){
3039 Arrays .sort (y );
3140 Arrays .sort (x );
3241 int horizontal = 1 ;
@@ -38,25 +47,29 @@ public static long cutBoard(int m, int n, long[] y, long[] x){
3847 while (i >=0 &&j >=0 ){
3948 if (y [i ]>=x [j ]){
4049 cost += vertical *y [i ];
50+ // if(cost>=mod) cost%=mod;
4151 i --;
4252 horizontal ++;
4353 }
4454 else {
4555 cost += horizontal *x [j ];
56+ // if(cost>=mod) cost%=mod;
4657 j --;
4758 vertical ++;
4859 }
4960 }
5061 while (j >=0 ){
5162 cost += horizontal *x [j ];
63+ // if(cost>=mod) cost%=mod;
5264 j --;
5365 vertical ++;
5466 }
5567 while (i >=0 ){
5668 cost += vertical *y [i ];
69+ // if(cost>=mod) cost%=mod;
5770 i --;
5871 horizontal ++;
5972 }
6073 return cost %mod ;
6174 }
62- }
75+ }
0 commit comments