提交记录 31436


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 noi19c. 【NOI2019】序列 Accepted 100 371.37 ms 16860 KB C++17 3.93 KB
提交时间 评测时间
2026-08-14 01:57:09 2026-08-14 01:57:21
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// state: 0 unused, 1 a-only, 2 b-only, 3 both
static int state[200005];
static ll a[200005], b[200005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; cin >> T;
    while(T--){
        int n, K, L; cin >> n >> K >> L;
        for(int i=0;i<n;i++) cin >> a[i];
        for(int i=0;i<n;i++) cin >> b[i];
        for(int i=0;i<n;i++) state[i]=0;

        vector<int> ordA(n), ordB(n);
        iota(ordA.begin(), ordA.end(), 0);
        iota(ordB.begin(), ordB.end(), 0);
        sort(ordA.begin(), ordA.end(), [&](int x,int y){ return a[x]>a[y]; });
        sort(ordB.begin(), ordB.end(), [&](int x,int y){ return b[x]>b[y]; });

        ll sum = 0;
        int overlap = 0;
        for(int t=0;t<K;t++){ int i = ordA[t]; state[i] |= 1; sum += a[i]; }
        for(int t=0;t<K;t++){
            int i = ordB[t];
            if(state[i]&1){ state[i]=3; overlap++; sum += b[i]; }
            else { state[i]=2; sum += b[i]; }
        }

        typedef pair<ll,int> P;
        priority_queue<P> qab0;      // max (a+b), state 0
        priority_queue<P, vector<P>, greater<P>> qamin; // min a, state 1
        priority_queue<P, vector<P>, greater<P>> qbmin; // min b, state 2
        priority_queue<P> qb1;       // max b, state 1
        priority_queue<P> qa2;       // max a, state 2
        priority_queue<P, vector<P>, greater<P>> qab3; // min (a+b), state 3

        for(int i=0;i<n;i++){
            if(state[i]==0) qab0.push({a[i]+b[i], i});
            else if(state[i]==1){ qamin.push({a[i],i}); qb1.push({b[i],i}); }
            else if(state[i]==2){ qbmin.push({b[i],i}); qa2.push({a[i],i}); }
            else { qab3.push({a[i]+b[i], i}); }
        }

        auto cl = [&](auto& pq, int need){
            while(!pq.empty() && state[pq.top().second]!=need) pq.pop();
        };

        while(overlap < L){
            cl(qab0,0); cl(qamin,1); cl(qbmin,2); cl(qb1,1); cl(qa2,2); cl(qab3,3);
            ll g1=LLONG_MIN, g2=LLONG_MIN, g3=LLONG_MIN, g4=LLONG_MIN;
            if(!qab0.empty() && !qamin.empty() && !qbmin.empty())
                g1 = qab0.top().first - qamin.top().first - qbmin.top().first;
            if(!qb1.empty() && !qbmin.empty())
                g2 = qb1.top().first - qbmin.top().first;
            if(!qa2.empty() && !qamin.empty())
                g3 = qa2.top().first - qamin.top().first;
            if(!qb1.empty() && !qa2.empty() && !qab3.empty())
                g4 = qb1.top().first + qa2.top().first - qab3.top().first;

            ll best = max(max(g1,g2), max(g3,g4));
            if(best == g1){
                int k=qab0.top().second, i=qamin.top().second, j=qbmin.top().second;
                state[k]=3; state[i]=0; state[j]=0;
                sum += g1;
                qab0.pop(); qamin.pop(); qbmin.pop();
                qab0.push({a[i]+b[i], i});
                qab0.push({a[j]+b[j], j});
                qab3.push({a[k]+b[k], k});
            } else if(best == g2){
                int k=qb1.top().second, j=qbmin.top().second;
                state[k]=3; state[j]=0;
                sum += g2;
                qb1.pop(); qbmin.pop();
                qab0.push({a[j]+b[j], j});
                qab3.push({a[k]+b[k], k});
            } else if(best == g3){
                int k=qa2.top().second, i=qamin.top().second;
                state[k]=3; state[i]=0;
                sum += g3;
                qa2.pop(); qamin.pop();
                qab0.push({a[i]+b[i], i});
                qab3.push({a[k]+b[k], k});
            } else {
                int i=qb1.top().second, j=qa2.top().second, k=qab3.top().second;
                state[i]=3; state[j]=3; state[k]=0;
                sum += g4;
                qb1.pop(); qa2.pop(); qab3.pop();
                qab3.push({a[i]+b[i], i});
                qab3.push({a[j]+b[j], j});
                qab0.push({a[k]+b[k], k});
            }
            overlap++;
        }
        cout << sum << "\n";
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #167.56 us76 KBAcceptedScore: 4

Testcase #277.57 us84 KBAcceptedScore: 4

Testcase #373.16 us80 KBAcceptedScore: 4

Testcase #486.31 us84 KBAcceptedScore: 4

Testcase #596.13 us84 KBAcceptedScore: 4

Testcase #6107 us88 KBAcceptedScore: 4

Testcase #7123.41 us88 KBAcceptedScore: 4

Testcase #8264.57 us92 KBAcceptedScore: 4

Testcase #9419.73 us100 KBAcceptedScore: 4

Testcase #10416.11 us100 KBAcceptedScore: 4

Testcase #111.59 ms152 KBAcceptedScore: 4

Testcase #124.076 ms236 KBAcceptedScore: 4

Testcase #135.181 ms244 KBAcceptedScore: 4

Testcase #145.226 ms264 KBAcceptedScore: 4

Testcase #155.223 ms264 KBAcceptedScore: 4

Testcase #165.367 ms248 KBAcceptedScore: 4

Testcase #1729.086 ms1020 KBAcceptedScore: 4

Testcase #1847.92 ms3 MB + 956 KBAcceptedScore: 4

Testcase #19121.19 ms15 MB + 876 KBAcceptedScore: 4

Testcase #20126.024 ms16 MB + 96 KBAcceptedScore: 4

Testcase #2195.535 ms13 MB + 460 KBAcceptedScore: 4

Testcase #22204.069 ms12 MB + 756 KBAcceptedScore: 4

Testcase #23213.076 ms15 MB + 660 KBAcceptedScore: 4

Testcase #24371.37 ms16 MB + 476 KBAcceptedScore: 4

Testcase #25315.57 ms16 MB + 344 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-12 08:42:05 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠