-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbee1290.cpp
More file actions
57 lines (46 loc) · 1.01 KB
/
Copy pathbee1290.cpp
File metadata and controls
57 lines (46 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Contest : Beecrowd
* Problem : 1290 - Caixas Muito Especiais
* Link : https://judge.beecrowd.com/pt/problems/view/1290
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
ll n, m;
void sortDim(ll &x, ll &y, ll &z) {
ll a[3] = {x, y, z};
sort(a, a + 3);
x = a[0];
y = a[1];
z = a[2];
}
void solve() {
if (!n) return;
ll x, y, z, vol;
cin >> x >> y >> z;
sortDim(x, y, z);
vol = x * y * z;
map<vector<ll>, ll> freq;
for (ll i = 0; i < m; ++i) {
ll cx, cy, cz;
cin >> cx >> cy >> cz;
sortDim(cx, cy, cz);
freq[{cx, cy, cz}]++;
}
ll ans = 1e18;
for (auto &[d, cnt] : freq) {
if (cnt < n) continue;
auto cx = d[0], cy = d[1], cz = d[2];
auto cvol = cx * cy * cz;
if (x <= cx && y <= cy && z <= cz) { ans = min(ans, cvol - vol); }
}
if (ans == 1e18) cout << "impossible\n";
else
cout << ans << "\n";
}
int main() {
fastio
while (cin >> n >> m) solve();
return 0;
}