func_code_string: #include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   const long long MAXN = 1e6 + 5;   long long n, m, t;   struct NODE {     long long a, b;   } v[MAXN];   long long cmp1(NODE a, NODE b) { return a.a < b.a; }   long long a[MAXN], b[MAXN];   long long q[MAXN];   int main() {     cin >> t;     while (t--) {       cin >> m >> n;       for (long long i = 1; i <= n; i++) cin >> v[i].a >> v[i].b;       sort(v + 1, v + 1 + n, cmp1);       for (long long i = 1; i <= n; i++)         a[i] = v[i].a, b[i] = v[i].b, q[i] = q[i - 1] + a[i];       long long ans = 0;       for (long long i = 1; i <= n; i++) {         long long nowb = b[i];         long long index = lower_bound(a + 1, a + 1 + n, nowb) - a;         if (index == n + 1) {           ans = max(ans, a[i] + (m - 1) * b[i]);           continue;         }         if (index <= i) {           long long can = n - index + 1;           if (can >= m) {             ans = max(ans, q[n] - q[n - m]);             continue;           }           ans = max(ans, q[n] - q[index - 1] + b[i] * (m - can));         } else {           long long can = n - index + 1;           if (can >= m - 1) {             ans = max(ans, q[n] - q[n - m + 1] + a[i]);             continue;           }           ans = max(ans, q[n] - q[index] + a[i] + b[i] * (m - can - 1) +                              max(b[i], a[index]));         }       }       cout << ans << endl;     }   }   