Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <queue>
- #include <string>
- #include <cstring>
- #include <cassert>
- #include <iomanip>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <ctime>
- #include <cmath>
- #define forn(i, n) for(int i=0;i<n;++i)
- #define fore(i, l, r) for(int i = int(l); i <= int(r); ++i)
- #define sz(v) int(v.size())
- #define all(v) v.begin(), v.end()
- #define pb push_back
- #define mp make_pair
- #define x first
- #define y1 ________y1
- #define y second
- #define ft first
- #define sc second
- #define pt pair<int, int>
- template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
- template<typename X> inline X sqr(const X& a) { return a * a; }
- typedef long long li;
- typedef long double ld;
- using namespace std;
- const int INF = 1000 * 1000 * 1000;
- const ld EPS = 1e-9;
- const ld PI = acos(-1.0);
- const int N = 100 * 1000 + 13;
- set<pair<int, int> > was;
- int n;
- vector<pair<int, int> > a;
- vector<int> d[N];
- int cnt[N];
- inline void read() {
- cin >> n;
- for (int i = 0; i < n; i++) {
- int x, y, z;
- cin >> x >> y >> z;
- a.pb(mp(x, i));
- a.pb(mp(y, i));
- a.pb(mp(z, i));
- d[i].pb(x);
- d[i].pb(y);
- d[i].pb(z);
- sort(all(d[i]));
- }
- }
- inline void solve() {
- sort(all(a));
- int now = 0;
- int ans = INF;
- for (int i = 0; i < sz(a); i++) {
- int idx = a[i].sc;
- if (cnt[idx] < 2) {
- was.insert(a[i]);
- cnt[idx]++;
- if (cnt[idx] == 2) now++;
- } else {
- was.erase(mp(d[idx][0], idx));
- was.insert(a[i]);
- }
- if (now == n) {
- ans = min(ans, (*was.rbegin()).ft - (*was.begin()).ft);
- }
- }
- cout << ans << endl;
- }
- int main () {
- #ifdef fcspartakm
- freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif
- srand(time(NULL));
- cerr << setprecision(10) << fixed;
- read();
- solve();
- //cerr << "TIME: " << clock() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement