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

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 T (1≤T≤100) — the number of queries. Next T lines contain descriptions of queries — one per line.

This line contains three integers str, int and exp (1≤str,int≤10^8,0≤exp≤10^8) — 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
4
5 3 4
2 1 0
3 5 5
4 10 6
output
3
1
2
0
Note

In the first query there are only three appropriate character builds: (str=7,int=5), (8,4) and (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).

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

In the fourth query all builds have too much brains.

先解释下题意:给定T行输入,每行输入三个整数str,int,exp。每点exp可以增加一点str或int,求str>int的方案共有多少种。

显然我们只要求出最少要加几点str使str>int就可以求出答案了。

下面给出代码,这里是用二分来求解。

#include <bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
cin>>a>>b>>c;
int l=0,r=c;
while(l<=r)
{
int mid=(l+r)/2;
if(a+mid>b+c-mid)
{
r=mid-1;
}
else
{
l=mid+1;
}
}
cout<<c-l+1<<endl;
}
return 0;
}

  

最新文章

  1. 【C++设计模式】单件类与DCLP(Double Check Lock Pattern)的风险
  2. jdbc java数据库连接 1)jdbc入门
  3. Winform程序Chrome内核 WebBrowser 控件
  4. AT指令(中文详解版)(一)
  5. Linux常用指令---快捷键
  6. Python: Lambda Functions
  7. ios自定义View自动布局时计算大小
  8. hdu 2176 取(m)石子游戏
  9. 计数排序之python 实现源码
  10. (推荐)jquery.pagination.js分页
  11. hadoop源码编译
  12. 一个Python小白5个小时爬虫经历
  13. python爬虫从入门到放弃(一)之初识爬虫
  14. XML约束(3)
  15. 【转载】[ORACLE]详解not in与not exists的区别与用法
  16. Java使用Redis实现分布式锁来防止重复提交问题
  17. 【Vijos】lxhgww的奇思妙想(长链剖分)
  18. 基于 Dropbear &amp; Zlib 搭建轻量级的ssh server
  19. 如何通过DataGridView 实现单元格合并和二维表头
  20. Elasticsearch - 理解字段分析过程(_analyze与_explain)

热门文章

  1. Python协程理解——基于爬虫举例
  2. Binary Tree和Binary Search Tree
  3. vue - data 接收 props 的值
  4. 10. Regular Expression Matching正则表达式匹配
  5. 123.ModelForm的使用
  6. Day4 - H - Following Orders POJ - 1270
  7. 009.Delphi插件之QPlugins,服务的热插拔
  8. svn全局设置过滤文件没有作用的解决办法
  9. python基础数据类型--元组(tuple)
  10. c#实现&quot;扫描检测硬件改动&quot;