题目传送门
1 /*
2 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1
3 二分搜索:搜索r,求出sum <= t * m的最大的r
4 详细解释:http://blog.csdn.net/libin56842/article/details/45082747
5 */
6 #include <cstdio>
7 #include <algorithm>
8 #include <cstring>
9 #include <cmath>
10 using namespace std;
11
12 typedef long long ll;
13
14 const int MAXN = 1e4 + 10;
15 const int INF = 0x3f3f3f3f;
16 ll A, B, n, l, t, m;
17
18 ll cal(ll x) {return A + (x - 1) * B;}
19
20 ll get_sum(ll l, ll r)
21 {
22 return (cal (l) + cal (r)) * (r - l + 1) / 2;
23 }
24
25 int main(void) //Codeforces Round #299 (Div. 2) C. Tavas and Karafs
26 {
27 while (scanf ("%I64d%I64d%I64d", &A, &B, &n) == 3)
28 {
29 for (int i=1; i<=n; ++i)
30 {
31 scanf ("%I64d%I64d%I64d", &l, &t, &m);
32 if (cal (l) > t) {puts ("-1"); continue;}
33 ll x = l; ll r = (t - A) / B + 1;
34 while (x <= r)
35 {
36 ll mid = (x + r) / 2;
37 if (get_sum (l, mid) <= t * m) x = mid + 1;
38 else r = mid - 1;
39 }
40 printf ("%d
", r);
41 }
42
43 }
44
45 return 0;
46 }