Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bai1;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class Bai1
- {
- public static int [] A = new int [6];
- public static int N,K,min,max,kq,dem;
- public static void main (String [] args) throws FileNotFoundException
- {
- File file = new File("input.txt");
- Scanner scanner = new Scanner(file);
- N = scanner.nextInt();
- K = scanner.nextInt();
- for (int i=0;i<N;i++) A[i]=scanner.nextInt();
- kq = 0;
- for (int i=0;i<N;i++)
- {
- dem = 1; min = A[i]; max = A[i];
- for (int j=i+1;j<N;j++)
- {
- if ((Math.abs(A[j]-min)<=K)&(Math.abs(A[j]-max)<=K)) dem++;
- else break;
- if (A[j]>max) max = A[j];
- if (A[j]<min) min = A[j];
- if (dem>kq) kq = dem;
- }
- }
- System.out.print(kq);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement