C. Tavas and Karafs
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 issi = 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 lt and m and you should find the largest number r such thatl ≤ r and 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.

Input

The first line of input contains three integers AB 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.

Output

For each query, print its answer in a single line.

Examples
input
  1. 2 1 4
    1 5 3
    3 3 10
    7 10 2
    6 4 8
output
  1. 4
    -1
    8
    -1
input
  1. 1 5 2
    1 5 10
    2 7 4
output
  1. 1
    2

题意:给一个等差数列,基为a,差为b,每次能对m个值减一,给出范围l,m,和次数t,求最能是得有边为0的最大值;

题解:二分找到符合的位置;

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<fstream>
  5. #include<cmath>
  6. #include<string>
  7. #include<vector>
  8. #include<algorithm>
  9. #include<string>
  10. #define ll long long
  11. using namespace std;
  12. ll a,b,n,m,l,t;
  13. ll slove(ll x)
  14. {
  15. ll ans=(a*+(l+x-)*b)*(x-l+)/;
  16. return ans;
  17. }
  18. bool judge(ll x)
  19. {
  20. if(a+(x-)*b>t)return true;
  21. if(slove(x)>t*m)return true;
  22. return false;
  23. }
  24. int main()
  25. {
  26. ios::sync_with_stdio(false);
  27. cin.tie();
  28. cin>>a>>b>>n;
  29. while(n--)
  30. {
  31. cin>>l>>t>>m;
  32. if(a+(l-)*b>t)
  33. {
  34. cout<<-<<endl;continue;
  35. }
  36. ll L=l,R=1e9;
  37. while(R-L>=)
  38. {
  39. ll mid=(R+L)>>;
  40. if(judge(mid))
  41. {
  42. R=mid-;
  43. }
  44. else
  45. {
  46. L=mid+;
  47. }
  48. }
  49. cout<<L-<<endl;
  50. }
  51. return ;
  52. }

http://codeforces.com/contest/535/problem/C的更多相关文章

  1. codeforces.com/contest/325/problem/B

    http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...

  2. [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环

    E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...

  3. http://codeforces.com/contest/555/problem/B

    比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...

  4. http://codeforces.com/contest/610/problem/D

    D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. http://codeforces.com/contest/612/problem/D

    D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  6. http://codeforces.com/contest/536/problem/B

    B. Tavas and Malekas time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. http://codeforces.com/contest/838/problem/A

    A. Binary Blocks time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. http://codeforces.com/contest/402/problem/E

    E. Strictly Positive Matrix time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. codeforces.com/contest/251/problem/C

    C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. jmeter系列------参数关联

    接口请求中的一个变量需要用上一个接口道服务器返回响应的动态值(上个请求). 遇到这样的情况,我们就需要用到关联 例如用户A发表了一个一条微信朋友圈,用户B想对这条朋友圈进行评论,就需要先获取到这个朋友 ...

  2. HDMI转MIPI DSI芯片方案TC358870XBG

    型号:TC358870XBG功能:HDMI1.4b转MIPI DSI通信方式:IIC分辨率:2560*1600@60fps/4k*2k@30fps电源:3.3/1.8/1.2/1.1封装形式:BGA8 ...

  3. Tornado-数据库(torndb包)

    1.torndb数据库简介     在Tornado3.0版本以前提供tornado.database模块用来操作MySQL数据库,而从3.0版本开始,此模块就被独立出来,作为torndb包单独提供. ...

  4. 在STEP7 TIA PORTAL中,设置模块的地址和设备名(Device name)

    assign device name, ip address for PROFINET componet in TIA Portal 方法1: PLC --> online & diag ...

  5. IS-IS完整笔记

    IS-IS笔记大全 1.公开,ISO国际标准化组织(按照中文顺序翻译) 中间系统到中间系统 双栈.集成 数据传递机制 Cons面向连接网络服务(TCP) Clns缺少链接网络服务(UDP) Is-is ...

  6. js正则知识点

    正则主要是用来匹配有规律的字符串,也就是说你要写一个正则前你必须非常清楚该类型字符串的规则,(比如邮箱)如果你没了解邮箱的规则那么你正则无论怎么写都是错的. \w字符(字母数字下划线)\W非字符\s空 ...

  7. 必应词典英语学习APP案例分析

    一.调研,评测 1.在此次作业之前并没有听过这个学英语app,必应听起来就像英语单词bing,第一次听到觉得这个app很奇怪,但没有将它和英语挂上钩.但是使用一阵子之后我觉得这个名字很好上口,其次这个 ...

  8. 【2017集美大学1412软工实践_助教博客】团队作业10——项目复审与事后分析(Beta版本)

    写在前面的话 转眼轰轰烈烈本学期的软工实践就结束了,这个过程中想必在熬夜敲代码,激烈讨论中留下诸多回忆的同时,也收获了不少.恭喜所有团队完成了本阶段冲刺,此外,由于大家的贡献分给的都很平均,将个人贡献 ...

  9. 201521123014 《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 2. 书面作业 Q1. 代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通 ...

  10. 201521123111《Java程序设计》第2周学习总结

    1. 本章学习总结 这个星期感觉有点醉,整个人都有点迷茫,仿佛突然失去了方向,连java也难以平复所带来的焦躁的情绪.再加上认为周四早上是没有课的,所以忘记去上了.最近总感觉像咸鱼一样,无所事事,想打 ...