/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 24ms 844.0 KiB
#3 Wrong Answer 34ms 772.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define int long long int
//const int N = 1e5 + 10;

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int t;
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);

        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        int sum1 = 0;
        for (int i = 0; i < k; ++i) {
            sum1 += a[i];
        }

        int ans = sum1;

        for (int i = 1; i <= n - k; ++i) {
            sum1 = sum1 - a[i - 1] + a[i + k - 1];
            ans = min(ans, sum1);

            for (int j = 0; j < k; ++j) {
                for (int l = 0; l < i; ++l) {
                    int new_sum = sum1 - a[j] + a[l];
                    ans = min(ans, new_sum);
                }
                for (int l = i + k; l < n; ++l) {
                    int new_sum = sum1 - a[j] + a[l];
                    ans = min(ans, new_sum);
                }
            }
        }

        cout << ans << endl;
    }
}

Information

Submit By
Type
Submission
Problem
P1149 Swap and Minimize
Contest
LU IUJPC : Sylhet Division 2024 Replay Contest
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-10 13:40:59
Judged At
2024-12-10 13:40:59
Judged By
Score
1
Total Time
34ms
Peak Memory
844.0 KiB