Skip to content

Instantly share code, notes, and snippets.

@invatainfo
Created September 16, 2017 15:01
Show Gist options
  • Save invatainfo/0cdcea3f00dda83a937ba4a0225390dd to your computer and use it in GitHub Desktop.
Save invatainfo/0cdcea3f00dda83a937ba4a0225390dd to your computer and use it in GitHub Desktop.
#include <fstream.h>
ifstream f("bac.txt");
void main() {
int n, k, i, j, imax, s = 0, smax, x[10000], y, p;
f >> n >> k;
for (i = 1; i <= k; i++) {
f >> x[i];
s = s + x[i];
}
imax = 1;
smax = s;
i = 1;
for (j = k + 1; j <= n; j++) {
f >> x[j];
s = s - x[i] + x[j];
i++;
if (s > smax) {
smax = s;
imax = i;
}
}
cout << imax;
f.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment