题意:https://www.luogu.com.cn/problem/CF1036B
思路:首先考虑直接从起点到终点最多有多少滑步,可以发现坐标差为奇数的时候那么一定需要一步去走掉,所以我们奇数的时候为max-1,偶数为max(大的坐标)。然后我们考虑剩下的步怎么走,如果是偶数我们直接来回滑步即可,那么如果是奇数步呢,这个时候我们回归前面奇偶,奇数的时候我们可以用一个滑步加直走代替前面的奇数直走,那么最后的答案就是k-1。然后我们看偶数,偶数如果剩奇数步我们就用两个直走代替一个滑步,那么答案就是k-2。剩下的情况都是k。
/*keep on going and never give up*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define lowbit(x) x&(-x)
#define endl '\n'
#define wk is zqx ta die
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
int mx = max(n, m);
int mi = min(n, m);
if (mx > k) {
cout << "-1" << endl;
} else {
if ((mx - mi) % 2 != 0) {
cout << k - 1 << endl;
} else {
k -= mx;
if (k % 2) {
cout << (k + mx) - 2 << endl;
} else {
cout << k + mx << endl;
}
}
}
}
return 0;
}