-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhaybales.java
More file actions
69 lines (51 loc) · 1.73 KB
/
haybales.java
File metadata and controls
69 lines (51 loc) · 1.73 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
63
64
65
66
67
68
69
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
class set{
int start;
int end;
int num;
}
public class haybales {
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader f = new BufferedReader(new FileReader("haybales.in"));
// input file name goes above
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("haybales.out")));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int[] at = new int[n];
int q = Integer.parseInt(st.nextToken());
st = new StringTokenizer(f.readLine());
for(int i = 0; i< n; i++){
at[i]=Integer.parseInt(st.nextToken());
}
Arrays.sort(at);
for(int i: at){
System.out.print(i+" ");
}
System.out.println();
System.out.println();
ArrayList<set> m = new ArrayList<set>();
for(int i = 0; i<q;i++){
st = new StringTokenizer(f.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
int startind = Arrays.binarySearch(at,start);
int endind = Arrays.binarySearch(at,end);
System.out.println(startind+" "+endind);
if(startind<0){
startind+=1;
startind = -startind;
}
if(endind<0){
endind= endind+2;
endind = -endind;
}
System.out.println(startind+" "+endind);
out.println(endind - startind+1);
}
out.close();
}
}