/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 492.0 KiB
#2 Wrong Answer 14ms 616.0 KiB
#3 Wrong Answer 22ms 808.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
using ll = long long;
#define trace(x) cout << #x << ": " << x << endl
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
    	int n, k;
        cin >> n >> k;

        vector<int> v(n + 1);
        for (int i = 1; i <= n; i++)
            cin >> v[i];

        ll ans = 1e17, sum = 0, ind = -1, big = v[0], curr_big = v[0];

        for (int i = 1; i <= n; i++) {
            if (i > k) {
                sum -= v[i - k];
                // cout << sum << ' ';
                sum += v[i];
                // cout << sum << ' ';

                if (sum < ans) {
                    ans = sum;
                    ind = i;
                    // cout << big << ' ';
                    // if (big < v[i])
                    //     big = v[i];
                }
                if (big < v[i])
                        big = v[i];
            }
            else {
                sum += v[i];
                if (big < v[i])
                    big = v[i];
                // cout << big << ' ';
                ind = i;
                ans = sum;
                //cout << sum << ' ';
            }
        }

        // cout << ans << ' ' << big << '\n';

        int mn = 1e9;
        for (int i = 1; i <= n; i++) {
            if (i > min(ind, abs(k - ind)) and i <= max(ind, abs(k - ind)))
                continue;

            if (mn > v[i])
                mn = v[i];
        }

        // cout << mn  << ' ' << big << '\n';
        ans -= big;
        ans += mn;

        cout << ans << '\n';
        // cout << ind << '\n';
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1149 Swap and Minimize
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 09:22:02
Judged At
2024-12-09 09:22:02
Judged By
Score
1
Total Time
22ms
Peak Memory
808.0 KiB