Advertisement
ivnikkk

Untitled

Feb 9th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "bits/stdc++.h"
  3. //#include "geometry.h"
  4. //#include "data_structure.h"
  5. using namespace std;
  6. using namespace chrono;
  7. #define all(a) a.begin(), a.end()
  8. #define allr(a) a.rbegin(), a.rend()
  9. mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
  10. typedef long long ll;
  11. typedef double ld;
  12. signed main() {
  13. #ifdef _DEBUG
  14.     freopen("input.txt", "r", stdin);
  15.     freopen("output.txt", "w", stdout);
  16. #endif
  17.     srand(time(NULL));
  18.     ios_base::sync_with_stdio(false);
  19.     cin.tie(nullptr);
  20.     cout.tie(nullptr);
  21.     ll n = 1e5;
  22.     ll k = 1e4;
  23.     vector<ll> a(n);
  24.     for (ll i = 0; i < n; i++) {
  25.         cin >> a[i];
  26.     }
  27.     sort(all(a));
  28.     struct My{
  29.         ll cnt = 0;
  30.         ll start = 0;
  31.         ll ind = 0;
  32.     };
  33.     a.resize(unique(all(a)) - a.begin());
  34.     unordered_map<ll, My> used;
  35.     bool fl = true;
  36.     ll d = 0;
  37.     ll g = 0;
  38.     for (ll i = 0; i < n; i++) {
  39.         for (ll j = i + 1; j < n; j++) {
  40.             if (!used[a[j] - a[i]].start) {
  41.                 used[a[j] - a[i]].start = a[i];
  42.                 used[a[j] - a[i]].ind = i;
  43.             }
  44.             if (k - used[a[j] - a[i]].cnt > n - j) {
  45.                 used.erase(a[j] - a[i]);
  46.             }
  47.             used[a[j] - a[i]].cnt++;
  48.             if (used[a[j] - a[i]].cnt == k-1) {
  49.                 d = a[j] - a[i];
  50.                 ll cnt = 0;
  51.                 cout << used[a[j] - a[i]].start << '\n';
  52.                 ll last = used[a[j] - a[i]].ind;
  53.                 for (ll f = used[a[j] - a[i]].ind+1; f < n&& cnt != k - 1; f++) {
  54.                     if (a[f] - a[last] == d) {
  55.                         cout <<a[f]<<'\n';
  56.                         last = f;
  57.                         cnt++;
  58.                     }
  59.                 }
  60.                 return 0;
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement