/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 17ms 564.0 KiB
#3 Wrong Answer 25ms 860.0 KiB
#4 Wrong Answer 46ms 788.0 KiB

Code

#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define print(v) for(auto data : v) cout << data << " "; cout << endl;
using namespace std;
void solve()
{
    int n, k; cin >> n >> k;
    vector<ll> v(n); for(auto &data : v) cin >> data;
    int l = 0, r = 0;
    ll sum = 0;
    int L, R;
    
    ll ans = 2e5 + 50;
    while (r < n)
    {
        sum += v[r];
        if(r-l+1 == k)
        {
            ll mx = v[l];
            for (int i = l; i <= r; i++)
            {
                mx = max(mx, v[i]);
            }
            ll mn = mx;
            for (int i = 0; i < n; i++)
            {
                if(i >= l && i <= r) continue;
                mn = min(mn, v[i]);
            }
            ll tmp = sum;
            if(mx > mn)
            {
                tmp -= mx; 
                tmp += mn;
            }
            ans = min(ans, tmp);

            sum -= v[l]; l++;
        } 
        r++;
    }
    cout << ans << endl;
}
int main ()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int t; cin >> t;
    while (t--) solve();
    
    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:32:51
Judged At
2024-12-09 08:32:51
Judged By
Score
10
Total Time
46ms
Peak Memory
860.0 KiB