Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main {
- static Integer size, maxSize;
- static ArrayList<Integer> points;
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- size = in.nextInt();
- maxSize = in.nextInt();
- points = new ArrayList<>(size);
- for (int i = 0; i < size; i++) {
- points.add(in.nextInt());
- }
- Integer answ = 1;
- while (true) {
- Integer t = answ + points.get(0);
- Integer steps = 1;
- Boolean found = false;
- while (true) {
- if (!points.contains(t))
- break;
- else if (points.indexOf(t) == points.size() - 1){
- found = true;
- break;
- }else{
- t += answ;
- steps++;
- }
- }
- if(found && steps <= maxSize)
- break;
- answ ++;
- }
- System.out.println(answ);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement