|
| 1 | +package hackerRank.problem.practice; |
| 2 | + |
| 3 | +import java.io.*; |
| 4 | +import java.util.HashMap; |
| 5 | +import java.util.Map; |
| 6 | +import java.util.Map.Entry; |
| 7 | + |
| 8 | +public class Stats { |
| 9 | + public static void main(String[] args) throws IOException { |
| 10 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 11 | + PrintWriter wr = new PrintWriter(System.out); |
| 12 | + int T = Integer.parseInt(br.readLine().trim()); |
| 13 | + for (int t_i = 0; t_i < T; t_i++) { |
| 14 | + String[] arr = br.readLine().split(" "); |
| 15 | + long[] array = new long[3]; |
| 16 | + for (int i = 0; i < arr.length; i++) { |
| 17 | + array[i] = Long.parseLong(arr[i]); |
| 18 | + } |
| 19 | + long row = array[0]; |
| 20 | + long col = array[1]; |
| 21 | + long stampAvl = array[2]; |
| 22 | + |
| 23 | + long out_ = maxStampedArea(row, col, stampAvl); |
| 24 | + System.out.println(out_); |
| 25 | + } |
| 26 | + |
| 27 | + wr.close(); |
| 28 | + br.close(); |
| 29 | + } |
| 30 | + |
| 31 | + static long maxStampedArea(long row,long col, long stampAvl) |
| 32 | + { |
| 33 | + long maxStamp = Long.MIN_VALUE; |
| 34 | + long stampAvlCopy = stampAvl; |
| 35 | + long areaAvl = row * col; |
| 36 | + if(areaAvl <= stampAvl){ |
| 37 | + maxStamp = stampAvl; |
| 38 | + } |
| 39 | + else{ |
| 40 | + if(stampAvl%row == 0 || stampAvl%col ==0){ |
| 41 | + maxStamp = stampAvl; |
| 42 | + } |
| 43 | + else{ |
| 44 | + long sqStamp = calcSqStamp(row,col,stampAvl); |
| 45 | + boolean out = false; |
| 46 | + while(out == false){ |
| 47 | + stampAvlCopy--; |
| 48 | + out = calcMaxStamp(row,col,stampAvlCopy); |
| 49 | + } |
| 50 | + maxStamp = Math.max(sqStamp,stampAvlCopy); |
| 51 | + } |
| 52 | + } |
| 53 | + return maxStamp; |
| 54 | + } |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + static boolean calcMaxStamp(long row,long col, long stampAvl){ |
| 59 | + boolean flag = false; |
| 60 | + if(stampAvl%row == 0 || stampAvl%col ==0){ |
| 61 | + flag = true; |
| 62 | + } |
| 63 | + return flag; |
| 64 | + } |
| 65 | + static long calcSqStamp(long row,long col, long stampAvl){ |
| 66 | + if(row==col){ |
| 67 | + if(row*col < stampAvl){ |
| 68 | + return row*col; |
| 69 | + } |
| 70 | + else{ |
| 71 | + row--; |
| 72 | + col--; |
| 73 | + calcSqStamp(row,col,stampAvl); |
| 74 | + } |
| 75 | + return row * col; |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + return Long.MIN_VALUE; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments