Wrong Answer
Code
#include <stdio.h>
int main() {
int T;
scanf("%d", &T);
while (T--) {
int N, F;
scanf("%d %d", &N, &F);
int A[N];
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
int min_sum = 0;
for (int i = 0; i < F; i++) {
min_sum += A[i];
}
int current_sum = min_sum;
for (int i = 1; i <= N - F; i++) {
current_sum = current_sum - A[i - 1] + A[i + F - 1];
if (current_sum < min_sum) {
min_sum = current_sum;
}
}
for (int i = 0; i <= N - F; i++) {
int subarray[F];
for (int j = 0; j < F; j++) {
subarray[j] = A[i + j];
}
for (int j = 0; j < F; j++) {
for (int l = j + 1; l < F; l++) {
int temp = subarray[j];
subarray[j] = subarray[l];
subarray[l] = temp;
int new_sum = 0;
for (int m = 0; m < F; m++) {
new_sum += subarray[m];
}
if (new_sum < min_sum) {
min_sum = new_sum;
}
temp = subarray[j];
subarray[j] = subarray[l];
subarray[l] = temp;
}
}
}
printf("%d\n", min_sum);
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1149 Swap and Minimize
- Contest
- LU IUJPC : Sylhet Division 2024 Replay Contest
- Language
- C11 (GCC 13.2.0)
- Submit At
- 2024-12-10 11:51:48
- Judged At
- 2024-12-10 11:51:48
- Judged By
- Score
- 0
- Total Time
- 24ms
- Peak Memory
- 540.0 KiB