結果

問題 No.2852 Yakitori Optimization Problem
ユーザー HIcoder
提出日時 2024-08-25 22:05:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 117,368 KB
最終ジャッジ日時 2025-02-24 02:13:15
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP; 
const ll MOD=998244353;
const int MAXN=100000;

int main(){
    int N,K;
    cin>>N>>K;
    vector<ll> A(N),B(N),C(N);
    ll tot=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        tot+=A[i];
    }
    priority_queue<ll> pq;
    for(int i=0;i<N;i++){
        cin>>B[i];
        tot+=B[i];//全部塩と仮定
    }
    for(int i=0;i<N;i++){
        cin>>C[i];
    }
    for(int i=0;i<N;i++){
        ll dif=C[i]-B[i];
        pq.push(dif);
    }
    
    ll ans=tot;

    int cK=K,cT=N-K;
    while(!pq.empty() && cT>0){
        ll v =pq.top();pq.pop();
        ans+=v;
        cT--;
    }

    cout<<ans<<endl;
}
0