Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. //716A : CRAZY COMPUTER
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStream;
  8. import java.io.PrintWriter;
  9. import java.util.StringTokenizer;
  10.  
  11. //Your code goes here
  12. public class Main {
  13.  
  14. static class ProblemSolver{
  15. public void solveTheProblem(InputReader in,PrintWriter out){
  16. //Take the necessary inputs
  17. //Declare the necessary variables
  18. int n=in.nextInt();
  19. int words=1;
  20. int c=in.nextInt();
  21. int[] num=new int[n];
  22. for(int i=0;i<n;++i)num[i]=in.nextInt();
  23.  
  24. //Compute the result
  25. /*
  26. * If the difference is more than c then
  27. * the current word will come to the number
  28. * of words present i.e. 1 else we need to
  29. * increase the number of words
  30. */
  31. for(int i=1;i<n;++i){
  32. if(num[i]-num[i-1]<=c)++words;
  33. else words=1;
  34. }
  35.  
  36. //Display the result
  37. System.out.println(words);
  38. }
  39. }
  40.  
  41. //Default template for all the codes
  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. }
  67.  
  68. //Main method for all the codes
  69. public static void main(String[] args) {
  70. InputStream inputStream = System.in;
  71. OutputStream outputStream = System.out;
  72. InputReader in = new InputReader(inputStream);
  73. PrintWriter out = new PrintWriter(outputStream);
  74. ProblemSolver problemSolver = new ProblemSolver();
  75. problemSolver.solveTheProblem(in, out);
  76. out.close();
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement