Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <random>
- #include <algorithm>
- #pragma GCC optimize("Ofast,fast-math,unroll-loops,no-stack-protector,inline")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,abm,mmx,popcnt")
- using int64 = int;
- using namespace std;
- bool bs(vector<int64> &vec, int64 el) {
- int64 l = 0, r = vec.size();
- while (r - l > 1) {
- int64 m = (l + r) / 2;
- if (vec[m] > el) {
- r = m;
- } else {
- l = m;
- }
- }
- return vec[l] == el;
- }
- pair<int64, int64> Check(int64 a, int64 d, vector<int64> &vec) {
- int64 cnt = 1;
- int64 minim = a;
- while (minim - d >= vec[0] && bs(vec, minim - d)) {
- ++cnt;
- minim -= d;
- if (cnt == vec.size()/2){
- break;
- }
- }
- if (cnt < vec.size()/2){
- int64 maxi = a;
- while (maxi + d <= vec.back() && bs(vec, maxi + d)) {
- ++cnt;
- if (cnt == vec.size()/2){
- break;
- }
- maxi += d;
- }
- }
- return {cnt, minim};
- }
- mt19937 generator;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int64 n;
- cin >> n;
- vector<int64> vec(2 * n);
- map<int64, int64> counter;
- for (int64 i = 0; i < 2 * n; ++i) {
- cin >> vec[i];
- ++counter[vec[i]];
- if (counter[vec[i]] >= n) {
- cout << vec[i] << " 0" << "\n";
- return 0;
- }
- }
- sort(vec.begin(), vec.end());
- if (n == 1) {
- cout << vec[0] << " 0" "\n";
- return 0;
- }
- bool flag_odd = true;
- for (int64 i = 3; i < 2 * n - 2; i += 2) {
- if (vec[i] - vec[i - 2] != vec[i+2] - vec[i]){
- flag_odd = false;
- break;
- }
- }
- if (flag_odd){
- cout << vec[1] << " " << vec[3] - vec[1];
- return 0;
- }
- bool flag_even = true;
- for (int64 i = 2; i < 2 * n - 2; i += 2) {
- if (vec[i] - vec[i - 2] != vec[i+2] - vec[i]){
- flag_even= false;
- break;
- }
- }
- if (flag_even){
- cout << vec[0] << " " << vec[2] - vec[0];
- return 0;
- }
- while (true) {
- int64 l = (generator() % (2 * n) + 2 * n) % (2 * n);
- int64 r = (generator() % (2 * n) + 2 * n) % (2 * n);
- if (l >= r) continue;
- int64 diff = vec[r] - vec[l];
- for (int64 k = 1; k * k <= diff; ++k) {
- if (diff % k != 0) continue;
- auto [cnt, minim] = Check(vec[l], k, vec);
- if (cnt == n) {
- cout << minim << " " << k;
- return 0;
- }
- if (k * k == diff) continue;
- auto [cnt_2, minim_2] = Check(vec[l], n/k, vec);
- if (cnt_2 == n) {
- cout << minim_2 << " " << n / k;
- return 0;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement