-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathHomework.java
More file actions
62 lines (49 loc) · 1.32 KB
/
MathHomework.java
File metadata and controls
62 lines (49 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.net.*;
import com.google.gson.*;
public class MathHomework
{
public static void main( String[] args ) throws IOException
{
Scanner s = new Scanner( System.in );
int threshold = s.nextInt();
int n = s.nextInt();
List<Integer> aList = new ArrayList<Integer>();
for( int i = 0; i < n; i++ )
aList.add( s.nextInt() );
System.out.println( minNum( threshold, aList ) );
}
public static int minNum( int threshold, List<Integer> points )
{
int minPoint = points.get( 0 );
int maxPoint = points.get( 0 );
int count = 1;
int i = 0;
int n = points.size();
while( i < n )
{
int diff = maxPoint - minPoint;
if( threshold <= diff )
return count;
if( threshold > diff && i+1<n && (points.get( i + 1 )-minPoint) >= threshold )
{
return ++count;
}
if( i + 2 < n )
{
maxPoint = points.get( i + 2 );
i += 2;
count++;
}
else
{
return n;
}
}
return count;
}
}