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

Envío 3919

Problema 0x25 - Suma de un subarreglo grande

  • Autor: bryancalisto
  • Fecha: 2021-04-21 05:20:13 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.006 s 4 KBi
#2
Correcto
0.004 s 1 KBi
#3
Correcto
0.003 s 1 KBi
#4
Correcto
0.003 s 3 KBi
#5
Correcto
0.006 s 3 KBi
#6
Correcto
0.002 s 2 KBi
#7
Correcto
0.003 s 3 KBi
#8
Correcto
0.355 s 1 KBi
#9
Tiempo límite excedido
1.079 s 2 KBi
#10
Tiempo límite excedido
1.062 s 2 KBi
#11
Tiempo límite excedido
1.025 s 1 KBi
#12
Tiempo límite excedido
1.059 s 2 KBi
#13
Correcto
0.033 s 2 KBi
#14
Tiempo límite excedido
1.061 s 2 KBi
Puntos totales: 65 / 100

Código

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

int main()
{
  // int N, c, i = 0, k, *arr;
  int N, c, i = 0, k;
  int p, q;
  long long res;

  fscanf(stdin, "%d", &N);
  int arr[N];

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

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

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

  //leer cada consulta, calcular su resultado e imprimirlo
  for (i = 0; i < c; i++)
  {
    scanf(" %d %d", &p, &q);
    res = 0;

    for (k = p; k <= q; k++)
    {
      res += arr[k];
    }

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

  // free(arr);
  return 0;
}