fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int i, maior, menor, soma, teste=1;
  5. int temperatura[10000], n, m;
  6.  
  7. scanf("%d %d", &n, &m);
  8.  
  9. while (n > 0) {
  10. //lê as temperaturas e calcula o somatório do primeiro intervalo
  11. soma = 0;
  12. for (i = 0; i < m; i++) {
  13. scanf("%d", &temperatura[i]);
  14. soma += temperatura[i];
  15. }
  16.  
  17. maior = soma;
  18. menor = soma;
  19.  
  20. //Calcula a soma dos outros intervalos usando a soma do intervalo anterior
  21. for (i=m; i < n; i++) {
  22. //for (; i < n; i++) {
  23. scanf("%d", &temperatura[i]);
  24. soma = soma + temperatura[i] - temperatura[i-m];
  25. if (soma > maior) {
  26. maior = soma;
  27. } else if (soma < menor) {
  28. menor = soma;
  29. }
  30. }
  31. printf("Teste %d\n%d %d\n\n", teste++, menor/m, maior/m);
  32.  
  33. scanf("%d %d", &n, &m);
  34. }
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 5644KB
stdin
4 2 
-5 
-12 
0 
6 
7 4 
35 
-35 
5 
100 
100 
50 
50 
0 0
stdout
Teste 1
-8 3

Teste 2
26 75