diff --git a/COMPTE_RENDU.md b/COMPTE_RENDU.md
index 047bd95..029a223 100644
--- a/COMPTE_RENDU.md
+++ b/COMPTE_RENDU.md
@@ -92,7 +92,7 @@ La complexité de la fonction est de [O(n)] pour
- Optimisation de la fonction 4 nom du commit : "fonction 4 : O(n + J)". Emprunte : ff68d260a7a58441
-- Optimisation de la fonction 5 nom du commit : "". Emprunte : ff68d260a7a58441
+- Optimisation de la fonction 5 nom du commit : "EXO 4 - optimisation F5". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 6 nom du commit : "". Emprunte : ff68d260a7a58441
@@ -105,4 +105,4 @@ La complexité de la fonction est de [O(n)] pour
- Optimisation de la fonction 10 nom du commit : "fonction 10 : O(L)". Emprunte : ff68d260a7a58441
-Le temps minimal atteint avec les modification est de 1.821 secondes.
+Le temps minimal atteint avec les modification est de 1.651 secondes.
diff --git a/banque b/banque
index 25e045c..fd1798f 100755
Binary files a/banque and b/banque differ
diff --git a/banque.c b/banque.c
index 5a48147..4bfd9ce 100644
--- a/banque.c
+++ b/banque.c
@@ -130,16 +130,20 @@ long meilleure_periode(const long *totaux, int nb_jours, int *debut, int *fin)
long meilleur = totaux[0];
*debut = 0;
*fin = 0;
- for (int i = 0; i < nb_jours; i++) {
- for (int j = i; j < nb_jours; j++) {
- long somme = 0;
- for (int k = i; k <= j; k++)
- somme += totaux[k];
- if (somme > meilleur) {
- meilleur = somme;
- *debut = i;
- *fin = j;
- }
+ long somme_courante = totaux[0];
+ int debut_courant = 0;
+
+ for (int j = 1; j < nb_jours; j++) {
+ if (somme_courante < 0) {
+ somme_courante = totaux[j];
+ debut_courant = j;
+ } else {
+ somme_courante += totaux[j];
+ }
+ if (somme_courante > meilleur) {
+ meilleur = somme_courante;
+ *debut = debut_courant;
+ *fin = j;
}
}
return meilleur;