136242025-01-08 11:30:51Leventusz09Sípálya (55 pont)cpp17Wrong answer 6/55500ms1148 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;

	vector<int> B(N); // Bájtra

	for (int i = 0; i < N; i++) cin >> B[i];

	int mp = INT_MAX;
	for (int i = 0, mi, s; i < N - K; i++) {
		mi = 0;
		s = 0;
		for (int j = i; j < i + K; j++) {
			s += B[j];
			if (B[j] >= B[mi]) mi = j;
		}

		/*for (int j = i; j < i + K; j++) {
			if (j < mi) sl += B[j];
			else if (j > mi) sr += B[j];
		}*/
		//int p = ((B[mi] + mi - i) + (B[mi] +1)) * (mi-i) / 2;
		//p += ((B[mi]-i-K+mi)+(B[mi]-1))*(i+K-mi)/2;
		int p = ((B[mi] + mi - i) + (B[mi] + mi - i - K + 1)) * K / 2;
		p -= s;
		if (p < mp) mp = p;
	}

	cout << mp << endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/55
1Accepted0/01ms500 KiB
2Accepted0/01ms316 KiB
3Accepted2/22ms316 KiB
4Wrong answer0/22ms316 KiB
5Wrong answer0/22ms316 KiB
6Wrong answer0/22ms316 KiB
7Wrong answer0/32ms316 KiB
8Wrong answer0/18ms440 KiB
9Wrong answer0/18ms508 KiB
10Wrong answer0/19ms436 KiB
11Wrong answer0/113ms436 KiB
12Wrong answer0/113ms316 KiB
13Wrong answer0/127ms508 KiB
14Accepted2/228ms432 KiB
15Accepted2/213ms436 KiB
16Time limit exceeded0/2500ms1080 KiB
17Time limit exceeded0/2500ms1076 KiB
18Time limit exceeded0/2500ms1076 KiB
19Time limit exceeded0/3500ms1044 KiB
20Time limit exceeded0/2481ms1076 KiB
21Time limit exceeded0/2500ms1076 KiB
22Time limit exceeded0/2500ms1076 KiB
23Time limit exceeded0/2500ms1076 KiB
24Time limit exceeded0/2481ms1076 KiB
25Time limit exceeded0/2500ms1076 KiB
26Time limit exceeded0/2500ms1076 KiB
27Time limit exceeded0/2500ms1076 KiB
28Time limit exceeded0/3479ms1148 KiB
29Time limit exceeded0/3500ms1076 KiB
30Time limit exceeded0/3500ms1076 KiB