結果

問題 No.2623 Room Allocation
ユーザー kaliafluoridokaliafluorido
提出日時 2024-02-09 22:03:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 4,106 bytes
コンパイル時間 8,892 ms
コンパイル使用メモリ 355,828 KB
実行使用メモリ 16,424 KB
最終ジャッジ日時 2024-02-09 22:03:17
合計ジャッジ時間 10,956 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 21 ms
7,124 KB
testcase_07 AC 21 ms
7,124 KB
testcase_08 AC 21 ms
7,124 KB
testcase_09 AC 21 ms
7,124 KB
testcase_10 AC 18 ms
14,420 KB
testcase_11 AC 19 ms
14,420 KB
testcase_12 AC 11 ms
8,644 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 48 ms
16,424 KB
testcase_15 AC 30 ms
6,676 KB
testcase_16 AC 8 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 30 ms
6,676 KB
testcase_19 AC 28 ms
6,676 KB
testcase_20 AC 30 ms
6,676 KB
testcase_21 AC 30 ms
6,676 KB
testcase_22 AC 23 ms
6,676 KB
testcase_23 AC 13 ms
6,676 KB
testcase_24 AC 29 ms
6,676 KB
testcase_25 AC 24 ms
6,676 KB
testcase_26 AC 4 ms
6,676 KB
testcase_27 AC 47 ms
11,268 KB
testcase_28 AC 24 ms
9,304 KB
testcase_29 AC 16 ms
8,944 KB
testcase_30 AC 47 ms
10,532 KB
testcase_31 AC 6 ms
6,676 KB
testcase_32 AC 17 ms
12,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define FOR(i, start, end) for (int i = start; i < (int)(end); ++i)
#define RFOR(i, rstart, rend) for (int i = rstart; i >= (int)(rend); --i)
#define REP(i, end) FOR(i, 0, end)
#define BIT(x, i) (((x)>>(i))&1)
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T> void read(T& val) {cin >> val;}
template<typename T, typename... Args> void read(T& val, Args&... args) {cin >> val;read(args...);}
#define DEF(type, ...) type __VA_ARGS__;read(__VA_ARGS__)
constexpr ll LINF = 1LL << 60;
constexpr int INF = 1 << 30;
template <typename T> using TREE = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using Graph = vector<vector<T>>;
template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<typename T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<typename T>void chmin(T &a, const T &b) { if (b<a) a=b; }
template<typename T> istream &operator>>(istream&is,vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> ostream &operator<<(ostream&os,const vector<T>&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"\n");}return os;}
/* 回文判定 */ bool isPalindrome(const string &s){int sz=s.size(); REP(i,sz/2){if(s[i]!=s[sz-1-i])return false;} return true;}
/* 座標圧縮 */ template<typename T> vector<int> compress(const vector<T>&A){vector<int> ret(A.size()); auto tmp = A; sort(ALL(tmp)); tmp.erase(unique(ALL(tmp)), tmp.end()); REP(i,A.size()) ret[i] = lower_bound(ALL(tmp), A[i]) - tmp.begin(); return ret;}
/* 約数列挙 整数nの約数のvectorを返す */ vector<ll> enumdiv(ll n){vector<ll>s; for(ll i = 1;i*i<=n;i++){if(n%i==0){s.push_back(i);if(i*i!=n)s.push_back(n/i);}}return s;}
/* 素因数分解 pair<素数、指数>のvectorを返す */ vector<pll> primeDecomposition(ll x){vector<pll> ret;ll tmp=x;for(ll i=2;i*i<=x;++i){if(tmp%i==0){ll cnt=0; while(tmp%i==0){tmp/=i;++cnt;}ret.emplace_back(i,cnt);}}if(tmp!=1)ret.emplace_back(tmp,1);return ret;}
/* エラトステネスの篩 n未満の素数を列挙。isprimeには素数かどうかが入っている */ vector<bool> isprime;vector<int> era(int n) {isprime.resize(n, true);vector<int> res;isprime[0] = false; isprime[1] = false;for (int i = 2; i < n; ++i){if (isprime[i]) {res.push_back(i);for (int j = i*2; j < n; j += i) isprime[j] = false;}}return res;}
/* トポロジカルソート */ vector<int> topo_sort(const Graph<int> &G){int n = G.size();vector<int> deg(n), ret;for(const auto &v:G)for(const auto &to:v) ++deg[to];queue<int> que;REP(i,n) if(deg[i]==0)que.push(i);while(!que.empty()){const int from = que.front();que.pop();ret.push_back(from);for(const auto &to:G[from])if(--deg[to]==0) que.push(to);}return ret;};
using mint = modint998244353;
//using mint = modint1000000007;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n,x,y;
	cin >> n >> x >> y;
	vector<int> P(n);
	vector<char> C(n);
	REP(i,n) cin >> P[i] >> C[i];
	int m = x+y;
	vector<ll> A(m),B(m);
	REP(i,n){
		if(C[i]=='A') A[i%m] += P[i];
		else B[i%m] += P[i];
	}
	ll ans = 0;
	int cnt_a=0;
	REP(i,m){
		if(A[i] > B[i]){
			ans += A[i];
			cnt_a++;
		}
		else ans += B[i];
	}
	if(cnt_a > x){
		vector<ll> diff;
		REP(i,m){
			if(A[i] > B[i]){
				diff.push_back(A[i]-B[i]);
			}
		}
		sort(ALL(diff));
		REP(i,cnt_a-x){
			ans -= diff[i];
		}
	}else if(cnt_a < x){
		vector<ll> diff;
		REP(i,m){
			if(A[i] <= B[i]){
				diff.push_back(B[i]-A[i]);
			}
		}
		sort(ALL(diff));
		REP(i,x-cnt_a){
			ans -= diff[i];
		}
	}
	cout << ans << endl;

	return 0;
}
0