Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. #define IN "a.in"
  5. #define OUT "a.out"
  6.  
  7. //#define fin cin
  8. //#define fout cout
  9.  
  10. using namespace std;
  11.  
  12. ifstream fin ( IN ) ;
  13. ofstream fout ( OUT ) ;
  14.  
  15. int main()
  16. {
  17. long long a , b , n ;
  18. fin >> a >> b >> n ;
  19. for ( register int i = 1 ; i <= n ; ++ i ){
  20. long long l , t , m ;
  21. fin >> l >> t >> m ;
  22. long long st = 1 ;
  23. long long dr = 2000000 ;
  24. long long ans = -1 ;
  25. while ( st <= dr ) {
  26. long long mij = ( st + dr ) / 2 ;
  27. long long lb = l ;
  28. long long ub = mij ;
  29. if ( a + ( mij - 1 ) * b <= t and ( ub - lb + 1 ) * a + ( ( ( ub - 1 ) * ub ) / 2 - ( ( lb - 1 ) * ( lb - 2 ) ) / 2 ) * b <= m * t ){
  30. ans = mij ;
  31. st = mij + 1 ;
  32. }
  33. else dr = mij - 1 ;
  34. }
  35. fout << ans << '\n' ;
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement