답안 #873760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873760 2023-11-15T16:53:20 Z MilosMilutinovic 학교 설립 (IZhO13_school) C++14
50 / 100
198 ms 29016 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, s;
  cin >> n >> m >> s;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) {
    return a[i] > a[j] || (a[i] == a[j] && b[i] < b[j]);
  });
  vector<int> new_a(n), new_b(n);
  for (int i = 0; i < n; i++) {
    new_a[i] = a[order[i]];
    new_b[i] = b[order[i]];
  }
  a = new_a;
  b = new_b;
  order.clear();
  for (int i = m; i < n; i++) {
    order.push_back(i);
  }
  sort(order.begin(), order.end(), [&](int i, int j) {
    return b[i] > b[j];
  });
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    ans += a[i];
  }
  for (int i = 0; i < s; i++) {
    ans += b[order[i]];
  }
  multiset<int> L;
  for (int i = 0; i < m; i++) {
    L.insert(-a[i] + b[i]);
  }
  multiset<pair<int, int>> R;
  multiset<int> Ra;
  multiset<pair<int, int>> Rab;
  for (int i = 0; i < s; i++) {
    R.emplace(-b[order[i]], order[i]);
    Rab.emplace(-b[order[i]] + a[order[i]], order[i]);
  }
  for (int i = s; i < (int) order.size(); i++) {
    Ra.insert(a[order[i]]);
  }
  long long res = ans;
  while (!L.empty() && !R.empty()) {
    assert(!Rab.empty());
    res += *prev(L.end());
    L.erase(prev(L.end()));
    if (Ra.empty() || prev(Rab.end())->first > prev(R.end())->first + *prev(Ra.end())) {
      auto it = prev(Rab.end());
      res += it->first;
      int i = it->second;
      R.erase(R.find({-b[i], i}));
      Rab.erase(it);
    } else {
      {
        auto it = prev(R.end());
        res += it->first;
        int i = it->second;
        R.erase(R.find({-b[i], i}));
        Rab.erase(Rab.find({-b[i] + a[i], i}));
      }
      {
        auto it = prev(Ra.end());
        res += *it;
        Ra.erase(it);
      }
    }
    ans = max(ans, res);
  }
  cout << ans << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 2 ms 604 KB Output isn't correct
8 Correct 2 ms 800 KB Output is correct
9 Incorrect 2 ms 796 KB Output isn't correct
10 Correct 2 ms 604 KB Output is correct
11 Incorrect 3 ms 984 KB Output isn't correct
12 Correct 3 ms 860 KB Output is correct
13 Incorrect 14 ms 3356 KB Output isn't correct
14 Incorrect 42 ms 7540 KB Output isn't correct
15 Correct 92 ms 13196 KB Output is correct
16 Correct 133 ms 21704 KB Output is correct
17 Incorrect 143 ms 22484 KB Output isn't correct
18 Incorrect 149 ms 22868 KB Output isn't correct
19 Incorrect 173 ms 25508 KB Output isn't correct
20 Incorrect 198 ms 29016 KB Output isn't correct