fork download
  1. import java.io.*;
  2. import java.util.Locale;
  3. import java.util.StringTokenizer;
  4.  
  5. public class TaskA {
  6. private final InputReader reader;
  7. private final OutputWriter writer;
  8.  
  9. public TaskA(InputReader reader, OutputWriter writer) {
  10. this.reader = reader;
  11. this.writer = writer;
  12. }
  13.  
  14. public static void main(String[] args) {
  15. InputReader reader = new InputReader(System.in);
  16. OutputWriter writer = new OutputWriter(System.out);
  17. new TaskA(reader, writer).run();
  18. writer.writer.flush();
  19. }
  20.  
  21. public void run() {
  22. long A = reader.nextInt();
  23. long B = reader.nextInt();
  24. int n = reader.nextInt();
  25. for (int i = 0; i < n; i++) {
  26. int l = reader.nextInt();
  27. int t = reader.nextInt();
  28. int m = reader.nextInt();
  29. long a = 0, b = 2 * Math.max(t, m) + 1;
  30. while (b - a > 1) {
  31. long q = (a + b) / 2;
  32. if (A + (l + q - 2) * 1l * B <= t && (A + (l - 1) * 1l * B) * 1l * q + B * 1l * q * (q - 1) / 2 <= m * 1l * t)
  33. a = q;
  34. else
  35. b = q;
  36. }
  37. writer.printf("%d\n", (a == 0) ? -1 : l + a - 1);
  38. }
  39. }
  40.  
  41.  
  42. static class InputReader {
  43. public BufferedReader reader;
  44. public StringTokenizer tokenizer;
  45.  
  46. public InputReader(InputStream stream) {
  47. reader = new BufferedReader(new InputStreamReader(stream), 32768);
  48. tokenizer = null;
  49. }
  50.  
  51. public String next() {
  52. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  53. try {
  54. tokenizer = new StringTokenizer(reader.readLine());
  55. } catch (IOException e) {
  56. throw new RuntimeException(e);
  57. }
  58. }
  59. return tokenizer.nextToken();
  60. }
  61.  
  62. public int nextInt() {
  63. return Integer.parseInt(next());
  64. }
  65.  
  66. public double nextDouble() {
  67. return Double.parseDouble(next());
  68. }
  69.  
  70. public long nextLong() {
  71. return Long.parseLong(next());
  72. }
  73. }
  74.  
  75. static class OutputWriter {
  76. public PrintWriter writer;
  77.  
  78. OutputWriter(OutputStream stream) {
  79. writer = new PrintWriter(stream);
  80. }
  81.  
  82. public void printf(String format, Object... args) {
  83. writer.print(String.format(Locale.ENGLISH, format, args));
  84. }
  85. }
  86. }
  87.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class TaskA is public, should be declared in a file named TaskA.java
public class TaskA {
       ^
1 error
stdout
Standard output is empty