• + 0 comments
    import java.io.*;
    import java.math.*;
    import java.security.*;
    import java.text.*;
    import java.util.*;
    import java.util.concurrent.*;
    import java.util.regex.*;
    
    class Result {
        public static List<Integer> serviceLane(int n, List<List<Integer>> cases,List<Integer> width ) {
        // Write your code here
        int start, end;
        
        List<Integer> res= new ArrayList<Integer>(); 
            for(int i=0;i<cases.size();i++){
                int min=Integer.MAX_VALUE;
                start=cases.get(i).get(0);
                end= cases.get(i).get(1);
                while(start<=end)
                {
                    if(min>width.get(start))
                    min=width.get(start);
                    start++;
                }
                res.add(min);
                
            }
            return res;
        }
    
    }
    
    public class Solution {
        public static void main(String[] args) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
    
            String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
            int n = Integer.parseInt(firstMultipleInput[0]);
    
            int t = Integer.parseInt(firstMultipleInput[1]);
    
            String[] widthTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
            List<Integer> width = new ArrayList<>();
    
            for (int i = 0; i < n; i++) {
                int widthItem = Integer.parseInt(widthTemp[i]);
                width.add(widthItem);
            }
    
            List<List<Integer>> cases = new ArrayList<>();
    
            for (int i = 0; i < t; i++) {
                String[] casesRowTempItems = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
                List<Integer> casesRowItems = new ArrayList<>();
    
                for (int j = 0; j < 2; j++) {
                    int casesItem = Integer.parseInt(casesRowTempItems[j]);
                    casesRowItems.add(casesItem);
                }
    
                cases.add(casesRowItems);
            }
    
            List<Integer> result = Result.serviceLane(n, cases, width);
    
            for (int i = 0; i < result.size(); i++) {
                bufferedWriter.write(String.valueOf(result.get(i)));
    
                if (i != result.size() - 1) {
                    bufferedWriter.write("\n");
                }
            }
    
            bufferedWriter.newLine();
    
            bufferedReader.close();
            bufferedWriter.close();
        }
    }