結果

問題 No.1708 Quality of Contest
ユーザー bonKotsubonKotsu
提出日時 2022-07-23 12:32:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 4,603 ms
コンパイル使用メモリ 272,228 KB
実行使用メモリ 28,148 KB
最終ジャッジ日時 2023-09-18 08:06:07
合計ジャッジ時間 14,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,160 KB
testcase_01 AC 4 ms
8,016 KB
testcase_02 AC 4 ms
8,020 KB
testcase_03 AC 9 ms
8,352 KB
testcase_04 AC 10 ms
8,332 KB
testcase_05 AC 11 ms
8,336 KB
testcase_06 AC 9 ms
8,228 KB
testcase_07 AC 9 ms
8,356 KB
testcase_08 AC 4 ms
8,284 KB
testcase_09 AC 356 ms
28,148 KB
testcase_10 AC 273 ms
16,384 KB
testcase_11 AC 389 ms
18,284 KB
testcase_12 AC 397 ms
19,392 KB
testcase_13 AC 354 ms
17,768 KB
testcase_14 AC 402 ms
20,496 KB
testcase_15 AC 457 ms
22,748 KB
testcase_16 AC 431 ms
22,632 KB
testcase_17 AC 365 ms
20,108 KB
testcase_18 AC 372 ms
20,188 KB
testcase_19 AC 395 ms
21,700 KB
testcase_20 AC 358 ms
19,752 KB
testcase_21 AC 436 ms
20,884 KB
testcase_22 AC 420 ms
20,088 KB
testcase_23 AC 449 ms
22,476 KB
testcase_24 AC 286 ms
16,836 KB
testcase_25 AC 289 ms
17,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };

int main() {
  int n, m; ll x;
  cin >> n >> m >> x;
  vector<int> a(n), b(n);
  vector<int> type[200005];
  rep(i,n) {
    cin >> a[i] >> b[i];
    b[i]--;
    type[b[i]].pb(a[i]);
  }
  rep(i,200005) {
    sort(all(type[i]));
    if (type[i].size()) type[i].pop_back();
  }
  int k;
  cin >> k;
  vector<int> c(k);
  rep(i,k) cin >> c[i];
  sort(all(c));
  priority_queue<P, vector<P>> q1, q2;
  rep(i,n) {
    q1.push({a[i]+x,b[i]});
  }
  set<int> used;
  vector<int> ord(n);
  int i = 0;
  while (i < n) {
    ll cand1 = 0, cand2 = 0;
    int val1 = 0, g1 = 0, val2 = 0, g2 = 0;
    bool flag1 = false, flag2 = true;
    if (!q1.empty()) {
      P p = q1.top(); q1.pop();
      val1 = p.fi, g1 = p.se;
      if (used.find(g1) != used.end()) continue;
      cand1 = val1;
      flag1 = true;
    }
    if (!q2.empty()) {
      P p = q2.top(); q2.pop();
      val2 = p.fi, g2 = p.se;
      cand2 = val2;
    }
    if (cand2 >= cand1) {
      ord[i] = cand2;
      i++;
      if (flag1) q1.push({val1, g1});
    } else {
      ord[i] = cand1;
      i++;
      for (auto val : type[g1]) q2.push({val,g1}); 
      used.insert(g1);
      if (flag2) q2.push({val2, g2});
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    auto ind = lower_bound(all(c),i)-c.begin();
    ans += (ll)ord[i-1]*(k-ind);
  }
  cout << ans << endl;


  return 0;
}
0