|
| 1 | +package Prep; |
| 2 | + |
| 3 | +import java.util.Scanner; |
| 4 | + |
| 5 | +// https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/practice-problems/algorithm/balanced-partition-818edecd/description/ |
| 6 | +public class balancedPartition { |
| 7 | + |
| 8 | + |
| 9 | +// public static String helper(String str) { |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +// } |
| 16 | + |
| 17 | + public static void main(String[] args) { |
| 18 | + |
| 19 | + Scanner sc = new Scanner(System.in); |
| 20 | + |
| 21 | + int t = Integer.parseInt(sc.nextLine().trim()); |
| 22 | + |
| 23 | + while (t-- > 0) { |
| 24 | + |
| 25 | + |
| 26 | + int house = Integer.parseInt(sc.nextLine().trim()); |
| 27 | + for (int i = 0; i < house; i++) { |
| 28 | + |
| 29 | + |
| 30 | + int x = sc.nextInt(); |
| 31 | + int y = sc.nextInt(); |
| 32 | + int h = sc.nextInt(); |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + } |
| 49 | + |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +// v.push_back({y-x,h}); |
| 55 | +// minn=min(minn,y-x); |
| 56 | +// maxx=max(maxx,y-x); |
| 57 | +// } |
| 58 | +// int l = minn, r = maxx; |
| 59 | +// int ans = r + 1; |
| 60 | +// bool f = 0;while(l<=r) |
| 61 | +// { |
| 62 | +// int mid = (l + r) / 2; |
| 63 | +// int val = mid; |
| 64 | +// int suma = 0, sumb = 0, sume = 0; |
| 65 | +// for (int i = 0; i < v.size(); i++) { |
| 66 | +// if (v[i].first < val) |
| 67 | +// suma += v[i].second; |
| 68 | +// else if (v[i].first == val) |
| 69 | +// sume += v[i].second; |
| 70 | +// else |
| 71 | +// sumb += v[i].second; |
| 72 | +// } |
| 73 | +// if (suma == sumb) { |
| 74 | +// f = 1; |
| 75 | +// break; |
| 76 | +// } |
| 77 | +// suma += sume; |
| 78 | +// if (suma > sumb) { |
| 79 | +// r = val - 1; |
| 80 | +// } else if (suma < sumb) { |
| 81 | +// l = val + 1; |
| 82 | +// } else { |
| 83 | +// f = 1; |
| 84 | +// break; |
| 85 | +// } |
| 86 | + |
| 87 | +// }if(f)cout<<"YES\n";else cout<<"NO\n"; |
| 88 | +// }return 0;} |
0 commit comments