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

Envío 4314

Problema 0x25 - Suma de un subarreglo grande

  • Autor: arturor72
  • Fecha: 2021-06-07 21:29:36 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.003 s 1 KBi
#2
Correcto
0.004 s 1 KBi
#3
Correcto
0.003 s 1 KBi
#4
Correcto
0.002 s 0 KBi
#5
Correcto
0.003 s 1 KBi
#6
Correcto
0.003 s 1 KBi
#7
Correcto
0.006 s 1 KBi
#8
Correcto
0.01 s 1 KBi
#9
Correcto
0.06 s 2 KBi
#10
Correcto
0.059 s 1 KBi
#11
Correcto
0.08 s 2 KBi
#12
Correcto
0.074 s 2 KBi
#13
Correcto
0.026 s 2 KBi
#14
Tiempo límite excedido
1.054 s 1 KBi
Puntos totales: 93 / 100

Código

#include<stdio.h>                                                               
                                                                                
int main(){                                                                     
    int n;                                                                      
    scanf("%d", &n);                                                            
    int arr[n];                                                                 
    int i=0;                                                                    
    for(i=0; i<n; i++){                                                         
        scanf("%d", &arr[i]);                                                   
    }                                                                           
    int consultas;                                                              
    scanf("%d", &consultas);                                                    
    int p,q;                                                                    
    int b=0;                                                                    
    int total=0;                                                                
    for(i=0; i<consultas; i++){                                                 
        scanf("%d %d", &p, &q);                                                 
        int diff=q-p;                                                           
        int diff2=p+(n-q);                                                      
        int tf=diff-2*diff2;                                                      
        if(b==0 && tf>=0){                                                      
            b=1;                                                                
            for(int j=0; j<n; j++) total+=arr[j];                               
        }                                                                       
        if(tf>=0){                                                              
            int totalp=0;                                                       
            int totalq=0;                                                       
            for(int j=0; j<p; j++) totalp+=arr[j];                              
            for(int j=q+1; j<n; j++) totalq+=arr[j];                            
            printf("%d\n", (total-totalp-totalq));                              
        }else{                                                                  
            int c=0;                                                            
            for(int j=p;j<=q;j++) c+=arr[j];                                    
            printf("%d\n",c);                                                   
        }                                                                       
    }                                                                           
    return 0;                                                                   
}