Language: C++

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
long long solve(const vector<pair<long long, long long> > &a, const vector<pair<long long, long long> > &b, const vector<pair<long long, long long> > &c, const vector<pair<long long, long long> > &xy) {
  long long x = 0, y = 0;
  for (auto pr : a) {
    x += pr.first;
    y += pr.second;
  }
  for (auto pr : b) {
    x += pr.first;
    y += pr.second;
  }
  for (auto pr : c) {
    x += pr.first;
    y += pr.second;
  }
  long long ans = x * x + y * y;
  // vector<pair<long long, long long> > v{{0, 0}};
  // for (auto pr : xy) {
  //   vector<pair<long long, long long> > tmp;
  //   for (auto ima : v) {
  //     tmp.emplace_back(ima.first + pr.first, ima.second + pr.second);
  //   }
  //   for (auto ima : tmp) {
  //     v.emplace_back(ima);
  //   }
  // }
  sort(ALL(xy));
  long long tmp_ans = 0;
  long long tx = 0, ty = 0;
  for (auto pr : xy) {
    tx += pr.first;
    ty += pr.second;
    long long cal = (x + tx) * (x + tx) + (y + ty) * (y + ty);
    if (cal < ans) break;
    tmp_ans = max(tmp_ans, cal);
  }
  reverse(ALL(xy));
  tx = 0; ty = 0;
  for (auto pr : xy) {
    tx += pr.first;
    ty += pr.second;
    long long cal = (x + tx) * (x + tx) + (y + ty) * (y + ty);
    if (cal < ans) break;
    tmp_ans = max(tmp_ans, cal);
  }
  vector<pair<long long, long long> > tmp(xy);
  for (auto &pr : tmp) swap(pr.first, pr.second);
  sort(ALL(tmp));
  long long tx = 0, ty = 0;
  for (auto pr : tmp) {
    tx += pr.first;
    ty += pr.second;
    long long cal = (x + tx) * (x + tx) + (y + ty) * (y + ty);
    if (cal < ans) break;
    tmp_ans = max(tmp_ans, cal);
  }
  reverse(ALL(tmp));
  tx = 0; ty = 0;
  for (auto pr : tmp) {
    tx += pr.first;
    ty += pr.second;
    long long cal = (x + tx) * (x + tx) + (y + ty) * (y + ty);
    if (cal < ans) break;
    tmp_ans = max(tmp_ans, cal);
  }
  return max(ans, tmp_ans);
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<long long> x(n), y(n); REP(i, n) cin >> x[i] >> y[i];
  vector<pair<long long, long long> > x1y1, x1y0, x1, x0, x0y1, x0y0, y1, y0;
  REP(i, n) {
    if (x[i] > 0) {
      if (y[i] > 0) x1y1.emplace_back(x[i], y[i]);
      else if (y[i] == 0) x1.emplace_back(x[i], y[i]);
      else x1y0.emplace_back(x[i], y[i]);
    } else if (x[i] == 0) {
      if (y[i] > 0) y1.emplace_back(x[i], y[i]);
      else if (y[i] < 0) y0.emplace_back(x[i], y[i]);
    } else {
      if (y[i] > 0) x0y1.emplace_back(x[i], y[i]);
      else if (y[i] == 0) x0.emplace_back(x[i], y[i]);
      else x0y0.emplace_back(x[i], y[i]);
    }
  }
  long long ans = 0;
  ans = max(ans, solve(x1y1, x1, y1, x1y0));
  ans = max(ans, solve(x1y0, x1, y0, x1y1));
  ans = max(ans, solve(x0y1, y1, x0, x1y1));
  ans = max(ans, solve(x1y1, y1, x1, x0y1));
  ans = max(ans, solve(x0y1, x0, y1, x0y0));
  ans = max(ans, solve(x0y0, x0, y0, x0y1));
  ans = max(ans, solve(x0y0, y0, x0, x1y0));
  ans = max(ans, solve(x1y0, y0, x1, x0y0));
  printf("%.12f\n", sqrt(ans));
  return 0;
}


Compiler output:
a.cc: In function 'long long int solve(const std::vector<std::pair<long long int, long long int> >&, const std::vector<std::pair<long long int, long long int> >&, const std::vector<std::pair<long long int, long long int> >&, const std::vector<std::pair<long long int, long long int> >&)':
a.cc:83:13: error: redeclaration of 'long long int tx'
   83 |   long long tx = 0, ty = 0;
      |             ^~
a.cc:63:13: note: 'long long int tx' previously declared here
   63 |   long long tx = 0, ty = 0;
      |             ^~
a.cc:83:21: error: redeclaration of 'long long int ty'
   83 |   long long tx = 0, ty = 0;
      |                     ^~
a.cc:63:21: note: 'long long int ty' previously declared here
   63 |   long long tx = 0, ty = 0;
      |                     ^~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]':
/usr/include/c++/14/bits/stl_algo.h:1062:18:   required from 'void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]'
 1062 |           std::iter_swap(__first, __last);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1089:21:   required from 'void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]'
 1089 |       std::__reverse(__first, __last, std::__iterator_category(__first));
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:71:10:   required from here
   71 |   reverse(ALL(xy));
      |   ~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:185:11: error: no matching function for call to 'swap(const std::pair<long long int, long long int>&, const std::pair<long long int, long long int>&)'
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:13:
/usr/include/c++/14/bits/exception_ptr.h:229:5: note: candidate: 'void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/usr/include/c++/14/bits/exception_ptr.h:229:25: note:   no known conversion for argument 1 from 'const std::pair<long long int, long long int>' to 'std::__exception_ptr::exception_ptr&'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |          ~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/bits/move.h:226:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/bits/stl_pair.h:60:
/usr/include/c++/14/type_traits: In substitution of 'template<bool _Cond, class _Tp> using std::__enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]':
/usr/include/c++/14/type_traits:2323:11:   required by substitution of 'template<class ... _Cond> using std::_Require = std::__enable_if_t<((bool)std::__and_<_Bn>::value)> [with _Cond = {std::__not_<std::__is_tuple_like<const std::pair<long long int, long long int> > >, std::is_move_constructible<const std::pair<long long int, long long int> >, std::is_move_assignable<const std::pair<long long int, long long int> >}]'
 2323 |     using _Require = __enable_if_t<__and_<_Cond...>::value>;
      |           ^~~~~~~~
/usr/include/c++/14/bits/move.h:226:5:   required by substitution of 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = const std::pair<long long int, long long int>]'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/stl_algobase.h:185:11:   required from 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]'
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1062:18:   required from 'void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]'
 1062 |           std::iter_swap(__first, __last);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1089:21:   required from 'void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]'
 1089 |       std::__reverse(__first, __last, std::__iterator_category(__first));
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:71:10:   required from here
   71 |   reverse(ALL(xy));
      |   ~~~~~~~^~~~~~~~~
/usr/include/c++/14/type_traits:138:11: error: no type named 'type' in 'struct std::enable_if<false, void>'
  138 |     using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'void std::iter_swap(_ForwardIterator1, _ForwardIterator2) [with _ForwardIterator1 = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >; _ForwardIterator2 = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]':
/usr/include/c++/14/bits/stl_algo.h:1062:18:   required from 'void std::__reverse(_RandomAccessIterator, _RandomAccessIterator, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]'
 1062 |           std::iter_swap(__first, __last);
      |           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1089:21:   required from 'void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<const pair<long long int, long long int>*, vector<pair<long long int, long long int> > >]'
 1089 |       std::__reverse(__first, __last, std::__iterator_category(__first));
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:71:10:   required from here
   71 |   reverse(ALL(xy));
      |   ~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/move.h:250:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)std::__is_swappable<_Tp>::value)> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  250 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/14/bits/move.h:250:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algobase.h:185:11: note:   mismatched types '_Tp [_Nm]' and 'const std::pair<long long int, long long int>'
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)'
 1089 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algobase.h:185:11: note:   types 'std::pair<_T1, _T2>' and 'const std::pair<long long int, long long int>' have incompatible cv-qualifiers
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)' (deleted)
 1106 |     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algobase.h:185:11: note:   types 'std::pair<_T1, _T2>' and 'const std::pair<long long int, long long int>' have incompatible cv-qualifiers
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
In file included from a.cc:19:
/usr/include/c++/14/sstream:1204:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_stringbuf<_CharT, _Traits, _Alloc>&, basic_stringbuf<_CharT, _Traits, _Alloc>&)'
 1204 |     swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1204:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algobase.h:185:11: note:   types 'std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>' and 'const std::pair<long long int, long long int>' have incompatible cv-qualifiers
  185 |       swap(*__a, *__b);
      |       ~~~~^~~~~~~~~~~~
/usr/include/c++/14/sstream:1212:5: note: can