/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 540.0 KiB
#2 Wrong Answer 16ms 496.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(a) cout << #a << "-->" << (a) << '\n';

int main()
{
    ios ::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n, k;
        cin >> n >> k;
        vector<int> v(n);
        for (int i = 0; i < n; i++)
        {
            cin >> v[i];
        }
        if (n == k)
        {
            ll sum=accumulate(v.begin(),v.end(),0LL);
            cout<<sum<<'\n';
        }
        else if (n == 1)
        {
            cout<<v[0]<<'\n';
        }
        else
        {
            ll sum = INT_MAX;
            for (int i = 0; i < n - 2; i++)
            {
                int j = i;
                int times = 0;
                ll ans = 0;
                while (times < k)
                {
                    ans += v[j];
                    j++;
                    times++;
                    if (times == k)
                    {
                        sum = min(ans, sum);
                        int u = j - 1;
                        ans -= v[u];
                        ans += v[j];
                        sum = min(ans, sum);
                    }
                }
            }
            ll sum2 = INT_MAX;
            for (int i = n - 1; i >= k - 0 - 1; i--)
            {
                int j = i;
                int times = 0;
                ll ans = 0;
                while (times < k)
                {
                    ans += v[j];
                    j--;
                    times++;
                    if (times == k)
                    {
                        sum2 = min(ans, sum2);
                        int u = j + 1;
                        ans -= v[u];
                        ans += v[j];
                        sum2 = min(ans, sum2);
                    }
                }
            }
            cout << min(sum, sum2) << '\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 08:56:26
Judged At
2024-12-09 08:56:26
Judged By
Score
0
Total Time
16ms
Peak Memory
540.0 KiB