我们观察第一次操作之后序列会变成什么样子,显然是形如:
然后我们发现,如果再进行一次操作,比如这次我们选择的下标是 ,那么序列会变成:
不难发现,如果我们需要第二次操作的结果,在第一次就可以直接做到。
所以有结论至多操作一次,操作完一次之后序列的 最小是 。
视实现的精细程度可以做到 或者 ,不过我好像不太精细。
#include "bits/stdc++.h"
#define int long long
#define f(i ,m ,n ,x) for (int i = (m) ; i <= (n) ; i += (x))
using arr = std :: array < int ,2 > ;
const int N = 1e6 + 25 ;
int n ;
std :: basic_string < arr > ps ;
signed main (void) {
std :: ios :: sync_with_stdio (false) ,
std :: cin.tie (nullptr) ,std :: cout.tie (nullptr) ;
std :: cin >> n ;
assert (n <= 1000000) ;
f (i ,1 ,n ,1) {
int x ,y ; std :: cin >> x >> y ;
assert (x > 0 && x <= 1000000000 && y > 0 && y <= 1000000000) ;
int d = std :: __gcd (x ,y) ; x /= d ,y /= d ;
ps += (arr){x ,y} ;
}
std :: sort (ps.begin () ,ps.end () ,[] (const arr &x ,const arr &y)
{ return x[0] * y[1] > y[0] * x[1] ;}) ;
arr ans = *ps.begin () ;
if (ans[0] <= ans[1]) {
ans = *ps.rbegin () ;
std :: cout << ans[0] << ' ' << ans[1] << '\n' ;
} else {
arr tmp = *ps.rbegin () ;
int x = tmp[0] * ans[1] ,y = tmp[1] * ans[0] ;
int d = std :: __gcd (x ,y) ; x /= d ,y /= d ;
std :: cout << x << ' ' << y << '\n' ;
}
return 0 ;
}