Advertisement
Goga21

Untitled

Jun 11th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. signed main() {
  8.     ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  9.  
  10.     int num_tests;
  11.     cin >> num_tests;
  12.  
  13.     while (num_tests--) {
  14.         int a, b, c, target;
  15.         cin >> a >> b >> c;
  16.  
  17.         vector<int> dims = {a, b, c};
  18.         sort(dims.begin(), dims.end());
  19.  
  20.         cin >> target;
  21.         set<tuple<int, int, int>> possible_triples, adjusted_triples;
  22.  
  23.         for (int i = 1; i <= a; ++i) {
  24.             for (int j = 1; j <= b; ++j) {
  25.                 if (target % i == 0 && (target / i) % j == 0) {
  26.                     int k = (target / i) / j;
  27.                     if (k <= c) {
  28.                         possible_triples.insert(make_tuple(i, j, k));
  29.                     }
  30.                 }
  31.             }
  32.         }
  33.        
  34.         for (const auto& triplet : possible_triples) {
  35.             vector<int> values = {get<0>(triplet), get<1>(triplet), get<2>(triplet)};
  36.             sort(values.begin(), values.end());
  37.             adjusted_triples.insert(make_tuple(dims[0] - values[0], dims[1] - values[1], dims[2] - values[2]));
  38.         }
  39.  
  40.         int max_volume = 0;
  41.  
  42.         for (const auto& triplet : adjusted_triples) {
  43.             int dx = get<0>(triplet), dy = get<1>(triplet), dz = get<2>(triplet);
  44.  
  45.             if (dx >= 0 && dy >= 0 && dz >= 0) {
  46.                 int volume = (dx + 1) * (dy + 1) * (dz + 1);
  47.                 max_volume = max(max_volume, volume);
  48.             }
  49.         }
  50.  
  51.         cout << max_volume << '\n';
  52.     }
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement