/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 22ms 616.0 KiB
#3 Wrong Answer 31ms 824.0 KiB

Code

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

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        vector<int> a(n);
        int prefix[n+1]={0};
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            prefix[i+1]+=prefix[i]+a[i];
        }
        int mini=INT_MAX,st=0,en=0;
        for(int i=0;i+k-1<n ;i++)
        {
            int mini2=min(mini,(prefix[i+k]-prefix[i]));
            if(mini2<mini)
            {
                mini=mini2;
                st=i;
                en=i+k-1;
            }
        }
        // cout<<st<<" "<<en;
        int maxi=INT_MIN;
        for(int i=st;i<=en;i++)
        {
            maxi=max(maxi,a[i]);
        }
        int mini3=mini;
        for(int i=0;i<n;i++)
        {
            if(i>=st && i<=en) continue;
            else
            {
                int x=mini-maxi+a[i];
                mini3=min(mini3,x);
            }
        }
        
        if(mini3<mini)
        {
            mini=mini3;
        }
        cout<<mini<<endl;
        
    }
    
    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 06:47:45
Judged At
2024-12-09 06:47:45
Judged By
Score
1
Total Time
31ms
Peak Memory
824.0 KiB