Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.
Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.
For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.
Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ rand sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.
The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).
Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.
For each query, print its answer in a single line.
2 1 4 1 5 3 3 3 10 7 10 2 6 4 8
4 -1 8 -1
1 5 2 1 5 10 2 7 4
1 2
首先给出a,b,n
这是一个由a开头,b为公差,长度无限的等差数列
然后n个询问。
输入l,t,m。
取这个数列从l开始,m个数,每一次这个数列中所有的数字-1。
当首尾变成0的时候,可以向后移,问最后t次之后,最长的0序列的右边界是多少。
emmmmm。。题意用的是别人的。~~~
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX_N = 1e5+9;
long long int p,m,t;
long long int a,b;
int vec[MAX_N];
bool cheak(int mid)
{
long long int temp =(mid - p +1)*(a+(p-1)*b + a+(mid-1)*b)/2;
//if(mid == 4) cout<<temp<<"!!!!"<<t*m<<"!!!!!!!!"<<a+(mid-1)*b<<"!!!!"<<t<<endl;
if(temp <= t*m && a+(mid-1)*b <=t) return true;
else return false;
}
int main()
{
int N,M,T;
while(cin>>a>>b>>N)
{
for(int i=0;i<N;i++)
{
scanf("%I64d%I64d%I64d",&p,&t,&m);
long long int l = p ,r = p+t+10;
while(l<=r)
{
int mid = (l+r)>>1;
if(cheak(mid))
{
l = mid + 1;
}
else
{
r = mid - 1;
}
}
if(l == p) cout<<"-1"<<endl;
else cout<<l-1<<endl;
}
}
return 0;
}