Pagini recente » Cod sursa (job #2631895) | Cod sursa (job #427422) | Cod sursa (job #566556) | Cod sursa (job #2799867) | Cod sursa (job #1769494)
#include <stdio.h>
#define max(a, b)(a > b ? a : b)
int main() {
FILE *fin = fopen("perle2.in", "r"), *fout = fopen("perle2.out", "w");
long long n, sc,scurent, smax = -999999999, elem, first, last, maxlast, lastc, firstc, maxfirst;
int i, k;
fscanf(fin, "%lld%lld", &n, &k);
sc = 0;
for(i = 1;i <= n;i++) {
fscanf(fin, "%lld", &elem);
elem -= k;
scurent = max(elem, sc + elem);
first = firstc;
if(elem > sc+elem)
first = i;
if(scurent > smax) {
maxfirst = first;
maxlast = i;
smax = scurent;
}
sc = scurent;
firstc = first;
}
fprintf(fout, "%lld", smax);
fclose(fin);
fclose(fout);
return 0;
}