結果
問題 |
No.1708 Quality of Contest
|
ユーザー |
|
提出日時 | 2022-07-23 12:32:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 506 ms / 2,000 ms |
コード長 | 1,834 bytes |
コンパイル時間 | 5,075 ms |
コンパイル使用メモリ | 260,956 KB |
最終ジャッジ日時 | 2025-01-30 13:19:08 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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; }