-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSolution.java
44 lines (38 loc) · 1.32 KB
/
Solution.java
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
package Practice.Algorithms.Implementation.ServiceLane;
import java.util.Scanner;
public class Solution {
private static int[] serviceLane(int[] width, int[][] cases) {
int[] result = new int[cases.length];
for (int i = 0; i < cases.length; i++) {
int start = cases[i][0];
int end = cases[i][1];
int min = Integer.MAX_VALUE;
for (int j = start; j <= end; j++) {
min = (width[j] < min) ? width[j] : min;
}
result[i] = min;
}
return result;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int t = in.nextInt();
int[] width = new int[n];
for (int width_i = 0; width_i < n; width_i++) {
width[width_i] = in.nextInt();
}
int[][] cases = new int[t][2];
for (int cases_i = 0; cases_i < t; cases_i++) {
for (int cases_j = 0; cases_j < 2; cases_j++) {
cases[cases_i][cases_j] = in.nextInt();
}
}
int[] result = serviceLane(width, cases);
for (int i = 0; i < result.length; i++) {
System.out.print(result[i] + (i != result.length - 1 ? "\n" : ""));
}
System.out.println("");
in.close();
}
}