Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <cmath>
  6. #include <queue>
  7. #include <string>
  8. #include <cstring>
  9. #include <cassert>
  10. #include <iomanip>
  11. #include <algorithm>
  12. #include <set>
  13. #include <map>
  14. #include <ctime>
  15. #include <cmath>
  16.  
  17. #define forn(i, n) for(int i=0;i<n;++i)
  18. #define fore(i, l, r) for(int i = int(l); i <= int(r); ++i)
  19. #define sz(v) int(v.size())
  20. #define all(v) v.begin(), v.end()
  21. #define pb push_back
  22. #define mp make_pair
  23. #define x first
  24. #define y1 ________y1
  25. #define y second
  26. #define ft first
  27. #define sc second
  28. #define pt pair<int, int>
  29.  
  30. template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
  31. template<typename X> inline X sqr(const X& a) { return a * a; }
  32.  
  33. typedef long long li;
  34. typedef long double ld;
  35.  
  36. using namespace std;
  37.  
  38. const int INF = 1000 * 1000 * 1000;
  39. const ld EPS = 1e-9;
  40. const ld PI = acos(-1.0);
  41.  
  42. const int N = 100 * 1000 + 13;
  43.  
  44. set<pair<int, int> > was;
  45. int n;
  46. vector<pair<int, int> > a;
  47. vector<int> d[N];
  48. int cnt[N];
  49.  
  50. inline void read() {   
  51.     cin >> n;
  52.     for (int i = 0; i < n; i++) {
  53.         int x, y, z;
  54.         cin >> x >> y >> z;
  55.         a.pb(mp(x, i));
  56.         a.pb(mp(y, i));
  57.         a.pb(mp(z, i));
  58.         d[i].pb(x);
  59.         d[i].pb(y);
  60.         d[i].pb(z);
  61.         sort(all(d[i]));
  62.     }
  63. }
  64.  
  65. inline void solve() {
  66.     sort(all(a));
  67.     int now = 0;
  68.     int ans = INF;
  69.     for (int i = 0; i < sz(a); i++) {
  70.         int idx = a[i].sc;
  71.         if (cnt[idx] < 2) {
  72.             was.insert(a[i]);
  73.             cnt[idx]++;
  74.             if (cnt[idx] == 2) now++;
  75.         } else {
  76.             was.erase(mp(d[idx][0], idx));
  77.             was.insert(a[i]);
  78.         }
  79.         if (now == n) {
  80.             ans = min(ans, (*was.rbegin()).ft - (*was.begin()).ft);
  81.         }
  82.     }
  83.     cout << ans << endl;
  84. }
  85.  
  86. int main () {
  87. #ifdef fcspartakm
  88.     freopen("input.txt", "r", stdin);
  89.     //freopen("output.txt", "w", stdout);
  90. #endif
  91.     srand(time(NULL));
  92.     cerr << setprecision(10) << fixed;
  93.    
  94.     read();
  95.     solve();
  96.  
  97.     //cerr << "TIME: " << clock() << endl;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement