/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 17ms 620.0 KiB
#3 Wrong Answer 23ms 540.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

//o-set
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//debugging tool
template<typename T>
void debug(string name, T value) {
    cerr << name << " = " << value << endl;
}

template<typename T, typename U>
void debug(string name, pair<T, U> value) {
    cerr << name << " = {" << value.first << ", " << value.second << "}" << endl;
}

template<typename T>
void debug(string name, vector<T> v) {
    cerr << name << " =[ ";
    for (size_t i = 0; i < v.size(); i++) {
        if (i) {
            cerr << ", ";
        }
        cerr << v[i];
    }

    cerr << "]" << endl;
}

template<typename T>
void debug(string name, set<T> v) {
    cerr << name << " =[ ";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            cerr << ", ";
        }
        cerr << *it;
    }

    cerr << "]" << endl;
}



template<typename T, typename U>
void debug(string name, map<T, U> v) {
    cerr << name << " =[ ";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            cerr << ", ";
        }
        cerr << it->first << ": " << it->second;
    }

    cerr << "]" << endl;
}

#define DEBUG(x)        debug(#x, x);

#define int             long long
#define endl            "\n"
#define rep(i, a, b)    for (int i = 0; i < b; i++)
#define fr(i, a, b)    for (int i = 0; i <= b; i++)

typedef vector<int>     vi;















void solve() {
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    for(int i=0;i<n;i++){
         cin>>v[i];
    }
    int l=0,r=k-1,mx=0;
    for(int i=0;i<k;i++){
         mx+=v[i];
    }
   // cout<<mx<<endl;
    int ans=mx-v[0];
   // cout<<ans<<endl;
    for(int i=k;i<n;i++){
         ans+=v[i];
       // cout<<ans<<" "<<mx<<endl;
         if(ans<mx){
            mx=ans;
            l=i-k;
            r=i;
         }
         ans-=v[i-k];
    }
    //cout<<l<<" "<<r<<endl;
    int mxval=INT_MIN;
    for(int i=l;i<=r;i++){
        mxval=max(mxval,v[i]);
    }
    
    int minVal=INT_MAX;
    for(int i=0;i<n;i++){
         if(i>=l && i<=r)continue;
         minVal=min(minVal,v[i]);
    }

    mx=min(mx,mx+minVal-mxval);
    //cout<<min
    cout<<mx<<endl;

}



signed main() {
    ios_base::sync_with_stdio(false);cin.tie(0);

    int tt;     cin >> tt;
    
    while (tt--) 
        solve();
    
}

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 05:12:40
Judged At
2024-12-09 05:12:40
Judged By
Score
1
Total Time
23ms
Peak Memory
620.0 KiB