結果

問題 No.2623 Room Allocation
ユーザー OnjoujiToki
提出日時 2024-02-10 00:43:24
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 2,411 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 182,436 KB
実行使用メモリ 19,796 KB
最終ジャッジ日時 2024-09-28 16:47:24
合計ジャッジ時間 3,337 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

/* 💕💕💕💕💕
💗💗💗💗💗
  /)/)
( . .)
( づ💗

    💗💗💗  💗💗💗
  💗💗💗💗💗💗💗💗💗
  💗💗💗💗💗💗💗💗💗
    💗💗💗💗💗💗💗
      💗💗💗💗💗
        💗💗💗
          💗

*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T1, typename T2>
std::istream &operator>>(std::istream &is, std::pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  }
  return os;
}

template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

void solve() {
  int n, x, y;
  std::cin >> n >> x >> y;
  std::vector<std::pair<int, char>> a(n);
  for (auto &[p, c] : a) std::cin >> p >> c;
  std::vector<std::pair<long, long>> cnt(x + y);
  for (int i = 0; i < n; i++) {
    if (a[i].second == 'A')
      cnt[i % (x + y)].first += a[i].first;
    else
      cnt[i % (x + y)].second += a[i].first;
  }
  std::vector<std::pair<long long, long long>> ncnt;
  for (int i = 0; i < x + y; i++) {
    ncnt.emplace_back(cnt[i].first, cnt[i].second);
  }
  std::sort(ncnt.begin(), ncnt.end(), [&](auto &a, auto &b) {
    return a.first - a.second > b.first - b.second;
  });
  long long ans = 0;
  for (auto &[u, v] : ncnt) {
    // std::cout << u << " " << v << std::endl;
  }
  for (int i = 0; i < x; i++) {
    ans += ncnt[i].first;
  }
  for (int j = (int)ncnt.size() - 1; j >= x; j--) {
    ans += ncnt[j].second;
  }
  std::cout << ans << std::endl;
}
int main() {
  int t = 1;
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  // std::cin >> t;
  solve();

  return 0;
}
0