Codeforces|Leetcode|Codechef free solutions
Open in Telegram
Free codeforces, Codechef, Leetcode solutions are available 😍😍😍😍😍😍 Helped More than 200+ students to crack coding round in 2022 and helped placed them in Good companies. 🥳🥳🥳🤩🤩🤩 Dm @Cpsoln if you want help in coding round.
Show more4 317
Subscribers
No data24 hours
-137 days
-5230 days
Posts Archive
‼️‼️‼️‼️‼️‼️‼️‼️‼️
I will free code to my regular customer only
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc;
cin >> tc;
while (tc--)
{
long long int n;
cin >> n;
long long int sum = 0;
vector<long long int> local;
for (long long int i = 0; i < n; i++)
{
long long int a, b;
cin >> a >> b;
sum += (2 * min(a, b));
local.push_back(max(a, b));
}
sort(local.begin(), local.end());
sum += local[0];
sum += local[local.size() - 1];
for (long long int i = 1; i < local.size(); i++)
{
sum += local[i] - local[i - 1];
}
cout << sum << endl;
}
}
