/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 600.0 KiB
#2 Wrong Answer 26ms 604.0 KiB
#3 Wrong Answer 39ms 540.0 KiB

Code

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std ;
using namespace __gnu_pbds;
template<typename T>using o_set=tree<T,null_type,std::less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define opt() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+10 ;
const int mod= 1e9+7 ;
#define pb push_back
#define mp make_pair

int32_t main()
{
    opt();
    int tt=1;
    cin>>tt;
    for(int tc=1; tc<=tt; tc++)
    {
        int n,k;
        cin>>n>>k;
        vector<int>v(n);
        for(int i=0; i<n; i++)cin>>v[i];
        vector<int>vk(k);
        int sum=0;
        for(int i=0; i<k; i++)
        {
            sum+=v[i];
        }
        vector<pair<int,int>>vec;
        vec.pb({sum,0});
        int p=1;
        for(int i=1; i<n-k+1; i++)
        {
            sum-=v[i-1];
            sum+=v[i+k-1];
            vec.pb({sum,i});
            p++;
        }
        sort(vec.begin(),vec.end());
        int x=vec[0].second;
        vector<int>tmp(k);
        int j=0;
        for(int i=x; i<x+k; i++)
        {
            tmp[j]=v[i];
            j++;
        }
        sort(tmp.begin(),tmp.end());
        sort(v.begin(),v.end());
        int get=-1e18;
        bool f=false;
        for(int i=0; i<k; i++)
        {
            if(v[i]<tmp[i])
            {
                get=v[i];
                f=true;
                break;

            }
        }
       // for(int i=0;i<vec.size();i++)cout<<vec[i].first<<" "<<vec[0].second<<endl;

        int sum3=vec[0].first;
        if(f)
        {
            //sum3=vec[0].first;
            int sm1=tmp.back();
            sum3-=sm1;
            sum3+=get;
        }
        cout<<sum3<<endl;

    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1149 Swap and Minimize
Contest
LU IUJPC : Sylhet Division 2024
Language
C++11 (G++ 13.2.0)
Submit At
2024-12-09 06:05:07
Judged At
2024-12-09 06:05:07
Judged By
Score
1
Total Time
39ms
Peak Memory
604.0 KiB