[Educational Codeforces Round 72] A. Creating a Character (简单数学)

A. Creating a Character

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You play your favourite game yet another time. You chose the character you didn't play before. It has strstr points of strength and intint points of intelligence. Also, at start, the character has expexp free experience points you can invest either in strength or in intelligence (by investing one point you can either raise strength by 11 or raise intelligence by 11).

Since you'd like to make some fun you want to create a jock character, so it has more strength than intelligence points (resulting strength is strictly greater than the resulting intelligence).

Calculate the number of different character builds you can create (for the purpose of replayability) if you must invest all free points. Two character builds are different if their strength and/or intellect are different.

Input

The first line contains the single integer TT (1≤T≤1001≤T≤100) — the number of queries. Next TT lines contain descriptions of queries — one per line.

This line contains three integers strstr, intint and expexp (1≤str,int≤1081≤str,int≤108, 0≤exp≤1080≤exp≤108) — the initial strength and intelligence of the character and the number of free points, respectively.

Output

Print TT integers — one per query. For each query print the number of different character builds you can create.

Example

input

Copy

4
5 3 4
2 1 0
3 5 5
4 10 6

output

Copy

3
1
2
0

Note

In the first query there are only three appropriate character builds: (str=7,int=5)(str=7,int=5), (8,4)(8,4) and (9,3)(9,3). All other builds are either too smart or don't use all free points.

In the second query there is only one possible build: (2,1)(2,1).

In the third query there are two appropriate builds: (7,6)(7,6), (8,5)(8,5).

In the fourth query all builds have too much brains.

题意:

你被给与三个整数\(x,y,z\),你可以把\(\mathit z\) 拆分为\(z=a+b\) ,然后让\(a,b\)分别赋值给\(x,y\),即使\(x=x+a,y=y+b\)

现在问你有多少个种方式,使最后的\(x>y\)

思路:

先将\(\mathit z\) 全加到\(\mathit x\) 上,得\(x=x+z\),我们只需要从\(\mathit x\)中减去一个数,将其加给\(\mathit y\) ,且使\(x>y\)

等于求满足该不等式的a的数量,\(x-a>y+a\),化简:\(x-y>2*a\),由不等式性质我们知道:

\(\mathit a\)的取值数量为\(\lceil\frac{x-y}{2}\rceil\),又因为\(\mathit a\)有意义的取值范围是:\([0,z]\),所以答案为:

\(ans=min(max(\lceil\frac{x-y+z}{2}\rceil,0),z+1)\)

Ps:这题答案的上限和下限没思考清楚的很容易wa。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    int t;
    t = readint();
    while (t--)
    {
        ll x, y, z;
        x = readll();
        y = readll();
        z = readll();
        x = x + z - y;
        ll ans = 0ll;
        if (x > 0) {
            ans = x >> 1;
            if (x & 1)
            {
                ans++;
            }
        }
        ans = min(ans, z + 1ll);
        printf("%lld\n", ans );
    }

    return 0;
}