#pragma GCC optimize "-O3,omit-frame-pointer,inline,unroll-all-loops,fast-math" #pragma GCC target "tune=native" #include #include #include #include using namespace std; // Macros using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; // Types template using min_queue = priority_queue, greater>; template using max_queue = priority_queue; // Printing template void print_collection(ostream& out, T const& x); template void print_tuple(ostream& out, T const& a, index_sequence); namespace std { template ostream& operator<<(ostream& out, tuple const& x) { print_tuple(out, x, index_sequence_for{}); return out; } template ostream& operator<<(ostream& out, pair const& x) { print_tuple(out, x, index_sequence_for{}); return out; } template ostream& operator<<(ostream& out, array const& x) { print_collection(out, x); return out; } template ostream& operator<<(ostream& out, vector const& x) { print_collection(out, x); return out; } template ostream& operator<<(ostream& out, deque const& x) { print_collection(out, x); return out; } template ostream& operator<<(ostream& out, multiset const& x) { print_collection(out, x); return out; } template ostream& operator<<(ostream& out, multimap const& x) { print_collection(out, x); return out; } template ostream& operator<<(ostream& out, set const& x) { print_collection(out, x); return out; } template ostream& operator<<(ostream& out, map const& x) { print_collection(out, x); return out; } template ostream& operator<<(ostream& out, unordered_set const& x) { print_collection(out, x); return out; } } template void print_tuple(ostream& out, T const& a, index_sequence){ using swallow = int[]; out << '('; (void)swallow{0, (void(out << (I == 0? "" : ", ") << get(a)), 0)...}; out << ')'; } template void print_collection(ostream& out, T const& x) { int f = 0; out << '['; for(auto const& i: x) { out << (f++ ? "," : ""); out << i; } out << "]"; } // Random struct RNG { uint64_t s[2]; RNG(u64 seed) { reset(seed); } RNG() { reset(time(0)); } using result_type = u32; constexpr u32 min(){ return numeric_limits::min(); } constexpr u32 max(){ return numeric_limits::max(); } u32 operator()() { return randomInt32(); } static __attribute__((always_inline)) inline uint64_t rotl(const uint64_t x, int k) { return (x << k) | (x >> (64 - k)); } inline void reset(u64 seed) { struct splitmix64_state { u64 s; u64 splitmix64() { u64 result = (s += 0x9E3779B97f4A7C15); result = (result ^ (result >> 30)) * 0xBF58476D1CE4E5B9; result = (result ^ (result >> 27)) * 0x94D049BB133111EB; return result ^ (result >> 31); } }; splitmix64_state sm { seed }; s[0] = sm.splitmix64(); s[1] = sm.splitmix64(); } uint64_t next() { const uint64_t s0 = s[0]; uint64_t s1 = s[1]; const uint64_t result = rotl(s0 * 5, 7) * 9; s1 ^= s0; s[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b s[1] = rotl(s1, 37); // c return result; } inline u32 randomInt32() { return next(); } inline u64 randomInt64() { return next(); } inline u32 random32(u32 r) { return (((u64)randomInt32())*r)>>32; } inline u64 random64(u64 r) { return randomInt64()%r; } inline u32 randomRange32(u32 l, u32 r) { return l + random32(r-l+1); } inline u64 randomRange64(u64 l, u64 r) { return l + random64(r-l+1); } inline double randomDouble() { return (double)randomInt32() / 4294967296.0; } inline float randomFloat() { return (float)randomInt32() / 4294967296.0; } inline double randomRangeDouble(double l, double r) { return l + randomDouble() * (r-l); } template void shuffle(vector& v) { i32 sz = v.size(); for(i32 i = sz; i > 1; i--) { i32 p = random32(i); swap(v[i-1],v[p]); } } template void shuffle(T* fr, T* to) { i32 sz = distance(fr,to); for(int i = sz; i > 1; i--) { int p = random32(i); swap(fr[i-1],fr[p]); } } template inline int sample_index(vector const& v) { return random32(v.size()); } template inline T sample(vector const& v) { return v[sample_index(v)]; } } rng; // Letrec template class letrec_result { Fun fun_; public: template explicit letrec_result(T &&fun): fun_(forward(fun)) {} template decltype(auto) operator()(Args &&...args) { return fun_(ref(*this), forward(args)...); } }; template decltype(auto) letrec(Fun &&fun) { return letrec_result>(forward(fun)); } // Timer struct timer { chrono::high_resolution_clock::time_point t_begin; timer() { t_begin = chrono::high_resolution_clock::now(); } void reset() { t_begin = chrono::high_resolution_clock::now(); } float elapsed() const { return chrono::duration(chrono::high_resolution_clock::now() - t_begin).count(); } }; // Util template T& smin(T& x, T const& y) { x = min(x,y); return x; } template T& smax(T& x, T const& y) { x = max(x,y); return x; } template int sgn(T val) { if(val < 0) return -1; if(val > 0) return 1; return 0; } static inline string int_to_string(int val, int digits = 0) { string s = to_string(val); reverse(begin(s), end(s)); while((int)s.size() < digits) s.push_back('0'); reverse(begin(s), end(s)); return s; } // Debug static inline void debug_impl_seq() { cerr << "}"; } template void debug_impl_seq(T const& t, V const&... v) { cerr << t; if(sizeof...(v)) { cerr << ", "; } debug_impl_seq(v...); } /* pdqsort.h - Pattern-defeating quicksort. Copyright (c) 2015 Orson Peters This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ namespace pdqsort_detail { enum { // Partitions below this size are sorted using insertion sort. insertion_sort_threshold = 24, // Partitions above this size use Tukey's ninther to select the pivot. ninther_threshold = 128, // When we detect an already sorted partition, attempt an insertion sort that allows this // amount of element moves before giving up. partial_insertion_sort_limit = 8, // Must be multiple of 8 due to loop unrolling, and < 256 to fit in unsigned char. block_size = 64, // Cacheline size, assumes power of two. cacheline_size = 64 }; template struct is_default_compare : std::false_type { }; template struct is_default_compare> : std::true_type { }; template struct is_default_compare> : std::true_type { }; // Returns floor(log2(n)), assumes n > 0. template inline int log2(T n) { int log = 0; while (n >>= 1) ++log; return log; } // Sorts [begin, end) using insertion sort with the given comparison function. template inline void insertion_sort(Iter begin, Iter end, Compare comp) { typedef typename std::iterator_traits::value_type T; if (begin == end) return; for (Iter cur = begin + 1; cur != end; ++cur) { Iter sift = cur; Iter sift_1 = cur - 1; // Compare first so we can avoid 2 moves for an element already positioned correctly. if (comp(*sift, *sift_1)) { T tmp = std::move(*sift); do { *sift-- = std::move(*sift_1); } while (sift != begin && comp(tmp, *--sift_1)); *sift = std::move(tmp); } } } // Sorts [begin, end) using insertion sort with the given comparison function. Assumes // *(begin - 1) is an element smaller than or equal to any element in [begin, end). template inline void unguarded_insertion_sort(Iter begin, Iter end, Compare comp) { typedef typename std::iterator_traits::value_type T; if (begin == end) return; for (Iter cur = begin + 1; cur != end; ++cur) { Iter sift = cur; Iter sift_1 = cur - 1; // Compare first so we can avoid 2 moves for an element already positioned correctly. if (comp(*sift, *sift_1)) { T tmp = std::move(*sift); do { *sift-- = std::move(*sift_1); } while (comp(tmp, *--sift_1)); *sift = std::move(tmp); } } } // Attempts to use insertion sort on [begin, end). Will return false if more than // partial_insertion_sort_limit elements were moved, and abort sorting. Otherwise it will // successfully sort and return true. template inline bool partial_insertion_sort(Iter begin, Iter end, Compare comp) { typedef typename std::iterator_traits::value_type T; if (begin == end) return true; int limit = 0; for (Iter cur = begin + 1; cur != end; ++cur) { if (limit > partial_insertion_sort_limit) return false; Iter sift = cur; Iter sift_1 = cur - 1; // Compare first so we can avoid 2 moves for an element already positioned correctly. if (comp(*sift, *sift_1)) { T tmp = std::move(*sift); do { *sift-- = std::move(*sift_1); } while (sift != begin && comp(tmp, *--sift_1)); *sift = std::move(tmp); limit += cur - sift; } } return true; } template inline void sort2(Iter a, Iter b, Compare comp) { if (comp(*b, *a)) std::iter_swap(a, b); } // Sorts the elements *a, *b and *c using comparison function comp. template inline void sort3(Iter a, Iter b, Iter c, Compare comp) { sort2(a, b, comp); sort2(b, c, comp); sort2(a, b, comp); } template inline T* align_cacheline(T* p) { std::size_t ip = reinterpret_cast(p); ip = (ip + cacheline_size - 1) & -cacheline_size; return reinterpret_cast(ip); } template inline void swap_offsets(Iter first, Iter last, unsigned char* offsets_l, unsigned char* offsets_r, int num, bool use_swaps) { typedef typename std::iterator_traits::value_type T; if (use_swaps) { // This case is needed for the descending distribution, where we need // to have proper swapping for pdqsort to remain O(n). for (int i = 0; i < num; ++i) { std::iter_swap(first + offsets_l[i], last - offsets_r[i]); } } else if (num > 0) { Iter l = first + offsets_l[0]; Iter r = last - offsets_r[0]; T tmp(std::move(*l)); *l = std::move(*r); for (int i = 1; i < num; ++i) { l = first + offsets_l[i]; *r = std::move(*l); r = last - offsets_r[i]; *l = std::move(*r); } *r = std::move(tmp); } } // Partitions [begin, end) around pivot *begin using comparison function comp. Elements equal // to the pivot are put in the right-hand partition. Returns the position of the pivot after // partitioning and whether the passed sequence already was correctly partitioned. Assumes the // pivot is a median of at least 3 elements and that [begin, end) is at least // insertion_sort_threshold long. Uses branchless partitioning. template inline std::pair partition_right_branchless(Iter begin, Iter end, Compare comp) { typedef typename std::iterator_traits::value_type T; // Move pivot into local for speed. T pivot(std::move(*begin)); Iter first = begin; Iter last = end; // Find the first element greater than or equal than the pivot (the median of 3 guarantees // this exists). while (comp(*++first, pivot)); // Find the first element strictly smaller than the pivot. We have to guard this search if // there was no element before *first. if (first - 1 == begin) while (first < last && !comp(*--last, pivot)); else while ( !comp(*--last, pivot)); // If the first pair of elements that should be swapped to partition are the same element, // the passed in sequence already was correctly partitioned. bool already_partitioned = first >= last; if (!already_partitioned) { std::iter_swap(first, last); ++first; } // The following branchless partitioning is derived from "BlockQuicksort: How Branch // Mispredictions don’t affect Quicksort" by Stefan Edelkamp and Armin Weiss. unsigned char offsets_l_storage[block_size + cacheline_size]; unsigned char offsets_r_storage[block_size + cacheline_size]; unsigned char* offsets_l = align_cacheline(offsets_l_storage); unsigned char* offsets_r = align_cacheline(offsets_r_storage); int num_l, num_r, start_l, start_r; num_l = num_r = start_l = start_r = 0; while (last - first > 2 * block_size) { // Fill up offset blocks with elements that are on the wrong side. if (num_l == 0) { start_l = 0; Iter it = first; for (unsigned char i = 0; i < block_size;) { offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; } } if (num_r == 0) { start_r = 0; Iter it = last; for (unsigned char i = 0; i < block_size;) { offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); } } // Swap elements and update block sizes and first/last boundaries. int num = std::min(num_l, num_r); swap_offsets(first, last, offsets_l + start_l, offsets_r + start_r, num, num_l == num_r); num_l -= num; num_r -= num; start_l += num; start_r += num; if (num_l == 0) first += block_size; if (num_r == 0) last -= block_size; } int l_size = 0, r_size = 0; int unknown_left = (last - first) - ((num_r || num_l) ? block_size : 0); if (num_r) { // Handle leftover block by assigning the unknown elements to the other block. l_size = unknown_left; r_size = block_size; } else if (num_l) { l_size = block_size; r_size = unknown_left; } else { // No leftover block, split the unknown elements in two blocks. l_size = unknown_left/2; r_size = unknown_left - l_size; } // Fill offset buffers if needed. if (unknown_left && !num_l) { start_l = 0; Iter it = first; for (unsigned char i = 0; i < l_size;) { offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it; } } if (unknown_left && !num_r) { start_r = 0; Iter it = last; for (unsigned char i = 0; i < r_size;) { offsets_r[num_r] = ++i; num_r += comp(*--it, pivot); } } int num = std::min(num_l, num_r); swap_offsets(first, last, offsets_l + start_l, offsets_r + start_r, num, num_l == num_r); num_l -= num; num_r -= num; start_l += num; start_r += num; if (num_l == 0) first += l_size; if (num_r == 0) last -= r_size; // We have now fully identified [first, last)'s proper position. Swap the last elements. if (num_l) { offsets_l += start_l; while (num_l--) std::iter_swap(first + offsets_l[num_l], --last); first = last; } if (num_r) { offsets_r += start_r; while (num_r--) std::iter_swap(last - offsets_r[num_r], first), ++first; last = first; } // Put the pivot in the right place. Iter pivot_pos = first - 1; *begin = std::move(*pivot_pos); *pivot_pos = std::move(pivot); return std::make_pair(pivot_pos, already_partitioned); } // Partitions [begin, end) around pivot *begin using comparison function comp. Elements equal // to the pivot are put in the right-hand partition. Returns the position of the pivot after // partitioning and whether the passed sequence already was correctly partitioned. Assumes the // pivot is a median of at least 3 elements and that [begin, end) is at least // insertion_sort_threshold long. template inline std::pair partition_right(Iter begin, Iter end, Compare comp) { typedef typename std::iterator_traits::value_type T; // Move pivot into local for speed. T pivot(std::move(*begin)); Iter first = begin; Iter last = end; // Find the first element greater than or equal than the pivot (the median of 3 guarantees // this exists). while (comp(*++first, pivot)); // Find the first element strictly smaller than the pivot. We have to guard this search if // there was no element before *first. if (first - 1 == begin) while (first < last && !comp(*--last, pivot)); else while ( !comp(*--last, pivot)); // If the first pair of elements that should be swapped to partition are the same element, // the passed in sequence already was correctly partitioned. bool already_partitioned = first >= last; // Keep swapping pairs of elements that are on the wrong side of the pivot. Previously // swapped pairs guard the searches, which is why the first iteration is special-cased // above. while (first < last) { std::iter_swap(first, last); while (comp(*++first, pivot)); while (!comp(*--last, pivot)); } // Put the pivot in the right place. Iter pivot_pos = first - 1; *begin = std::move(*pivot_pos); *pivot_pos = std::move(pivot); return std::make_pair(pivot_pos, already_partitioned); } // Similar function to the one above, except elements equal to the pivot are put to the left of // the pivot and it doesn't check or return if the passed sequence already was partitioned. // Since this is rarely used (the many equal case), and in that case pdqsort already has O(n) // performance, no block quicksort is applied here for simplicity. template inline Iter partition_left(Iter begin, Iter end, Compare comp) { typedef typename std::iterator_traits::value_type T; T pivot(std::move(*begin)); Iter first = begin; Iter last = end; while (comp(pivot, *--last)); if (last + 1 == end) while (first < last && !comp(pivot, *++first)); else while ( !comp(pivot, *++first)); while (first < last) { std::iter_swap(first, last); while (comp(pivot, *--last)); while (!comp(pivot, *++first)); } Iter pivot_pos = last; *begin = std::move(*pivot_pos); *pivot_pos = std::move(pivot); return pivot_pos; } template inline void pdqsort_loop(Iter begin, Iter end, Compare comp, int bad_allowed, bool leftmost = true) { typedef typename std::iterator_traits::difference_type diff_t; // Use a while loop for tail recursion elimination. while (true) { diff_t size = end - begin; // Insertion sort is faster for small arrays. if (size < insertion_sort_threshold) { if (leftmost) insertion_sort(begin, end, comp); else unguarded_insertion_sort(begin, end, comp); return; } // Choose pivot as median of 3 or pseudomedian of 9. diff_t s2 = size / 2; if (size > ninther_threshold) { sort3(begin, begin + s2, end - 1, comp); sort3(begin + 1, begin + (s2 - 1), end - 2, comp); sort3(begin + 2, begin + (s2 + 1), end - 3, comp); sort3(begin + (s2 - 1), begin + s2, begin + (s2 + 1), comp); std::iter_swap(begin, begin + s2); } else sort3(begin + s2, begin, end - 1, comp); // If *(begin - 1) is the end of the right partition of a previous partition operation // there is no element in [begin, end) that is smaller than *(begin - 1). Then if our // pivot compares equal to *(begin - 1) we change strategy, putting equal elements in // the left partition, greater elements in the right partition. We do not have to // recurse on the left partition, since it's sorted (all equal). if (!leftmost && !comp(*(begin - 1), *begin)) { begin = partition_left(begin, end, comp) + 1; continue; } // Partition and get results. std::pair part_result = Branchless ? partition_right_branchless(begin, end, comp) : partition_right(begin, end, comp); Iter pivot_pos = part_result.first; bool already_partitioned = part_result.second; // Check for a highly unbalanced partition. diff_t l_size = pivot_pos - begin; diff_t r_size = end - (pivot_pos + 1); bool highly_unbalanced = l_size < size / 8 || r_size < size / 8; // If we got a highly unbalanced partition we shuffle elements to break many patterns. if (highly_unbalanced) { // If we had too many bad partitions, switch to heapsort to guarantee O(n log n). if (--bad_allowed == 0) { std::make_heap(begin, end, comp); std::sort_heap(begin, end, comp); return; } if (l_size >= insertion_sort_threshold) { std::iter_swap(begin, begin + l_size / 4); std::iter_swap(pivot_pos - 1, pivot_pos - l_size / 4); if (l_size > ninther_threshold) { std::iter_swap(begin + 1, begin + (l_size / 4 + 1)); std::iter_swap(begin + 2, begin + (l_size / 4 + 2)); std::iter_swap(pivot_pos - 2, pivot_pos - (l_size / 4 + 1)); std::iter_swap(pivot_pos - 3, pivot_pos - (l_size / 4 + 2)); } } if (r_size >= insertion_sort_threshold) { std::iter_swap(pivot_pos + 1, pivot_pos + (1 + r_size / 4)); std::iter_swap(end - 1, end - r_size / 4); if (r_size > ninther_threshold) { std::iter_swap(pivot_pos + 2, pivot_pos + (2 + r_size / 4)); std::iter_swap(pivot_pos + 3, pivot_pos + (3 + r_size / 4)); std::iter_swap(end - 2, end - (1 + r_size / 4)); std::iter_swap(end - 3, end - (2 + r_size / 4)); } } } else { // If we were decently balanced and we tried to sort an already partitioned // sequence try to use insertion sort. if (already_partitioned && partial_insertion_sort(begin, pivot_pos, comp) && partial_insertion_sort(pivot_pos + 1, end, comp)) return; } // Sort the left partition first using recursion and do tail recursion elimination for // the right-hand partition. pdqsort_loop(begin, pivot_pos, comp, bad_allowed, leftmost); begin = pivot_pos + 1; leftmost = false; } } } template inline void pdqsort(Iter begin, Iter end, Compare comp) { if (begin == end) return; pdqsort_detail::pdqsort_loop::type>::value && std::is_arithmetic::value_type>::value>( begin, end, comp, pdqsort_detail::log2(end - begin)); } template inline void pdqsort(Iter begin, Iter end) { typedef typename std::iterator_traits::value_type T; pdqsort(begin, end, std::less()); } template inline void pdqsort_branchless(Iter begin, Iter end, Compare comp) { if (begin == end) return; pdqsort_detail::pdqsort_loop( begin, end, comp, pdqsort_detail::log2(end - begin)); } template inline void pdqsort_branchless(Iter begin, Iter end) { typedef typename std::iterator_traits::value_type T; pdqsort_branchless(begin, end, std::less()); } const f64 TL = 0.98; timer TM; const i32 N = 45; i64 A[N], B[N]; void read(){ i32 n; cin>>n; do { if(!(n == N)) { throw runtime_error("main.cpp" ":" "11" " Assertion failed: " "n == N"); } } while(0); for(i32 i = 0; i < (i32)(N); ++i) cin>>A[i]>>B[i]; } struct p2 { i64 x,y; i64 m; p2(i64 x_, i64 y_, i64 m_){ x = x_; y = y_; m = m_; } p2() { x = y = m = 0; } p2& operator+=(p2 const& o) { x += o.x; y += o.y; m |= o.m; return *this; } p2 operator+(p2 const& o) const{ p2 r = *this; r += o; return r; } }; vector merge(vector const& A, vector const& B){ i64 ia = 0, ib = 0; i64 na = A.size(), nb = B.size(); vector out; out.reserve(na+nb); while(ia build(vector X) { vector Y = {p2()}; for(auto const& x : X) { auto L = Y, R = Y; for(auto& p : R) p += x; Y = merge(L, R); } return Y; } template void filter(V &v, Pred pred) { i32 sz = 0; for(i32 i = 0; i < (i32)(v.size()); ++i) if(pred(v[i])) { v[sz++] = v[i]; } v.resize(sz); } void print_answer(vector> ans) { cout << ans.size() << endl; for(auto [x,y] : ans) { cout << 1+x << " " << 1+y << endl; } } f64 GOAL = 5e17; struct llist { i32 elem; i32 nxt; }; const i32 LLIST_POOL_SIZE = 1<<24; llist llist_pool[LLIST_POOL_SIZE]; i32 llist_pool_next = 0; i32 make_llist(i32 e, i32 n) { llist_pool[llist_pool_next] = llist {e,n}; return llist_pool_next++; } struct state { f64 valuea, valueb; u64 available; f64 suma_available; f64 sumb_available; f64 heur_value; i32 history; void reset() { valuea = GOAL; valueb = GOAL; available = (1ll< recon() const { vector I; for(i32 i = 0; i < (i32)(N); ++i) if(available&(1ll< beam(1); beam[0].reset(); for(i32 step = 0; step < (i32)(N-2); ++step) { vector nbeam; nbeam.reserve(beam.size() * (N-step)); for(auto const& sa : beam) { for(i32 i = 0; i < (i32)(N); ++i) if(sa.available&(1ll< WIDTH) beam.resize(WIDTH); do { cerr << "main.cpp" ":" "158" " {" << "beam.size(), beam[0].heur_value" << "} = {"; debug_impl_seq(beam.size(), beam[0].heur_value); cerr << endl << flush; } while(0); } i64 best_score = 1e18; vector best_I; for(auto const& s : beam) { auto I = s.recon(); i64 a = A[I[0]], b = B[I[0]]; for(i32 i = (1); i <= (i32)(N-1); ++i) { a = (a+A[I[i]])/2; b = (b+B[I[i]])/2; } i64 score = max(abs(a-GOAL), abs(b-GOAL)); if(score < best_score) { best_score = score; best_I = I; } } vector> ans; for(i32 i = (0); i <= (i32)(N-2); ++i) { ans.push_back({best_I[i],best_I[i+1]}); best_I[i+1] = min(best_I[i], best_I[i+1]); } print_answer(ans); } i32 main(){ ios::sync_with_stdio(false); cin.tie(0); TM.reset(); read(); solve(); cerr << "Elapsed: " << TM.elapsed() << endl; cerr << "[DATA] time = " << TM.elapsed() << endl; return 0; }