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

Envío 3833

Problema 0x25 - Suma de un subarreglo grande

  • Autor: bryancalisto
  • Fecha: 2021-04-17 21:53:45 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.002 s 2 KBi
#2
Correcto
0.004 s 33 KBi
#3
Correcto
0.001 s 2 KBi
#4
Correcto
0.002 s 1 KBi
#5
Correcto
0.004 s 4 KBi
#6
Correcto
0.003 s 4 KBi
#7
Correcto
0.002 s 1 KBi
#8
Correcto
0.327 s 1 KBi
#9
Tiempo límite excedido
1.071 s 1 KBi
#10
Tiempo límite excedido
1.08 s 16 KBi
#11
Tiempo límite excedido
1.098 s 2 KBi
#12
Tiempo límite excedido
1.078 s 3 KBi
#13
Correcto
0.026 s 2 KBi
#14
Tiempo límite excedido
1.072 s 2 KBi
Puntos totales: 65 / 100

Código

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int N, c, i = 0, j, *arr, *consultas, res;

  fscanf(stdin, "%d", &N);

  arr = (int *)malloc(sizeof(int) * N);

  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
    ;

  fscanf(stdin, "%d", &c);

  consultas = (int *)malloc(sizeof(int) * c * 2);

  // leer cada consulta, calcular su resultado e imprimir resultado
  for (i = 0; i < c; i++)
  {
    j = 0;

    while (j < 2 && fscanf(stdin, "%d", consultas + i * 2 + j++) == 1)
      ;

    res = 0;

    for (int k = *(consultas + i * 2); k <= *(consultas + i * 2 + 1); k++)
    {
      res += arr[k];
    }

    printf("%d\n", res);
  }

  free(consultas);
  free(arr);
  return 0;
}