8184 | 2024-01-12 16:23:51 | szabelr | Sípálya (55 pont) | cpp17 | Compilation error |
#include <iostream>
using namespace std;
int epit(int h[], int s, int K, int N) {
int maxi = 0;
for (int i = 0; i < K; i++)
if (h[s+i]+i > h[s+maxi]+maxi) maxi = i;
/* cout << "maxi = " << maxi << endl; */
int m = h[s+maxi] - (K-1-maxi); // utolso lepcsofok magassaga
/* cout << "m = " << m << endl; */
int hs = 0;
for (int i = 0; i < K; i++) hs += h[s+i];
return K * (K-1) / 2 + K * m - hs;
}
int main() {
int N, K, h[200000];
cin >> N >> K;
for (int i = 0; i < N; i++) cin >> h[i];
int maxi = 0;
for (int i = 0; i < K; i++)
if (h[i]+i > h[maxi]+maxi) maxi = i;
int m = h[maxi] - (K-1-maxi); // utolso lepcsofok magassaga
int hs = 0;
for (int i = 0; i < K; i++) hs += h[i];
int minp = K * (K-1) / 2 + K * m - hs;
for (int s = 1; s < N-K+1; s++) {
/* int p = epit(h, s, K, N); */
maxi = 0;
for (int i = 0; i < K; i++)
if (h[s+i]+i > h[s+maxi]+maxi) maxi = i;
m = h[s+maxi] - (K-1-maxi); // utolso lepcsofok magassaga
hs = hs-h[s-1]+h[s+k-1];
//for (int i = 0; i < K; i++) hs += h[s+i];
int p = K * (K-1) / 2 + K * m - hs;
if (p < minp) minp = p;
}
cout << minp;
}
exit status 1
main.cpp: In function 'int main()':
main.cpp:43:28: error: 'k' was not declared in this scope
43 | hs = hs-h[s-1]+h[s+k-1];
| ^
Exited with error status 1