K
K
Kirill Grushkin2019-06-21 16:45:03
C++ / C#
Kirill Grushkin, 2019-06-21 16:45:03

How to rewrite code (C) to make it run faster?

#include <stdio.h>
#include <math.h>

int main(){
    int i,j,min,n;
    int size = 0;
        scanf("%i", &size);
        scanf("%i", &n);
    int N[size];
    for (i = 0; i <=(size-1); i++){
        scanf("%i", &N[i]);
    }

    for (i = 0; i <=(size-n); i++){
                min=N[i];
        for (j = 0; j <=(n-1); j++){
            if(N[i+j]<min){min=N[i+j];}
        }
        printf("%d\n",min);
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2019-06-21
@horoll

https://e-maxx.ru/algo/stacks_for_minima

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question