結果

問題 No.2852 Yakitori Optimization Problem
ユーザー graythunder1graythunder1
提出日時 2024-08-25 14:24:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 166,504 KB
実行使用メモリ 12,956 KB
最終ジャッジ日時 2024-08-25 14:24:28
合計ジャッジ時間 6,304 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
6,812 KB
testcase_01 AC 192 ms
12,120 KB
testcase_02 AC 158 ms
8,108 KB
testcase_03 AC 260 ms
12,080 KB
testcase_04 AC 209 ms
12,708 KB
testcase_05 AC 78 ms
6,944 KB
testcase_06 AC 26 ms
6,940 KB
testcase_07 AC 205 ms
11,388 KB
testcase_08 AC 20 ms
6,944 KB
testcase_09 AC 256 ms
12,912 KB
testcase_10 AC 266 ms
12,188 KB
testcase_11 AC 266 ms
12,188 KB
testcase_12 AC 269 ms
12,060 KB
testcase_13 AC 265 ms
12,956 KB
testcase_14 AC 266 ms
12,956 KB
testcase_15 AC 265 ms
12,572 KB
testcase_16 AC 264 ms
12,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N, K;
  cin >> N >> K;
  ll A[N], B[N], C[N];
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N) cin >> C[i];

  vector<pll> yakitori;
  rep(i, N) {
    yakitori.emplace_back(i, B[i]-C[i]);
  }

  sort(yakitori.begin(), yakitori.end(), [](pll a, pll b) {
    return a.second > b.second;
  });


  ll ans = 0;
  rep(i, N) {
    ll idx = yakitori[i].first;
    if (i < K) {
      ans += A[idx] + B[idx];
    } else {
      ans += A[idx] + C[idx];
    }
  }

  cout << ans << endl;
  return 0;
}

0