Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

//Dai Ca Di Hoc

#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define Rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define For(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define MIN(x,y) if (x > (y)) x = (y)
#define MAX(x,y) if (x < (y)) x = (y)
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define maxn 200005
#define MOD 1000000007
#define remain(x) if (x > MOD) x -= MOD
#define pii pair<int, int>
#define vi vector<int>
#define vii vector< pii >
#define bit(x, i) (((x) >> (i)) & 1)
#define Task "covercir"

using namespace std;

typedef long long int ll;

int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen(Task".inp", "r", stdin);
//freopen(Task".out", "w", stdout);
ll n, x, y;
int ntest; cin >> ntest;
while (ntest --){
cin >> n >> x >> y;

ll a = abs(x-y);
ll b = n - a;
if (a > b) swap(a,b);

ll d = b - 1; // cung lớn
ll c = max(0ll, a - 1); // cung nhỏ
ll c2 = c * 2; // 2 lần cung nhỏ, lặp lại

ll common = ((d - c) / 3) * 2 + (d - c) % 3; // cùng di chuyển sau khi hết


cung nhỏ
ll ans_0 = c + common;
ll ans_1 = d;
if (d > c2) { // đi cung nhỏ xong, đi tiếp
ll rest = (d - c2) / 2 + (d - c2) % 2; // đi tiếp sau x2 vòng nhỏ
ans_1 = c2 + rest;
}
cout << min(ans_0, ans_1) << endl;
}

return 0;
}

You might also like