█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6895

Problema 0x9b - Máximo elemento en un subarreglo pequeño

  • Autor: Aaron Zuñiga
  • Fecha: 2023-02-26 03:17:16 UTC (Hace alrededor de 1 año)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.11 s 13 KBi
#2
Correcto
0.096 s 13 KBi
#3
Correcto
0.096 s 13 KBi
#4
Correcto
0.165 s 14 KBi
#5
Correcto
0.114 s 13 KBi
#6
Correcto
0.083 s 17 KBi
#7
Correcto
0.172 s 13 KBi
#8
Correcto
0.121 s 13 KBi
#9
Correcto
0.119 s 13 KBi
#10
Correcto
0.133 s 22 KBi
#11
Correcto
0.62 s 85 KBi
#12
Correcto
0.745 s 84 KBi
#13
Correcto
0.563 s 85 KBi
Puntos totales: 100 / 100

Código

import java.util.Scanner;
class Main
{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        
        int c = sc.nextInt();
        for(int i = 0; i < c; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            resolve(a,l,r);    
        }
    }
    
    public static void resolve(int[] a,int l, int r){
        int mayor = Integer.MIN_VALUE; int x = 0;
        for(int i = l; i <= r; i++){
            if(a[i] > mayor){
                mayor = a[i];
                x = i;
            }
        }
        System.out.println(x);
    }
}