結果

問題 No.2623 Room Allocation
ユーザー TairitsuMeowTairitsuMeow
提出日時 2024-02-09 21:35:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 170,844 KB
実行使用メモリ 12,644 KB
最終ジャッジ日時 2024-02-09 21:35:42
合計ジャッジ時間 3,179 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 17 ms
10,596 KB
testcase_07 AC 17 ms
10,596 KB
testcase_08 AC 19 ms
10,596 KB
testcase_09 AC 20 ms
10,596 KB
testcase_10 AC 9 ms
8,548 KB
testcase_11 AC 9 ms
8,548 KB
testcase_12 AC 5 ms
8,548 KB
testcase_13 AC 6 ms
8,548 KB
testcase_14 AC 32 ms
12,644 KB
testcase_15 AC 23 ms
6,676 KB
testcase_16 AC 7 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 22 ms
6,676 KB
testcase_19 AC 21 ms
6,676 KB
testcase_20 AC 22 ms
6,676 KB
testcase_21 AC 23 ms
6,676 KB
testcase_22 AC 17 ms
6,676 KB
testcase_23 AC 11 ms
6,676 KB
testcase_24 AC 24 ms
6,676 KB
testcase_25 AC 19 ms
6,676 KB
testcase_26 AC 4 ms
6,676 KB
testcase_27 AC 40 ms
12,644 KB
testcase_28 AC 17 ms
10,596 KB
testcase_29 AC 11 ms
8,548 KB
testcase_30 AC 39 ms
12,644 KB
testcase_31 AC 4 ms
6,676 KB
testcase_32 AC 8 ms
8,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.2623 Room Allocation
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2623
// Memory Limit: 512 MB
// Time Limit: 2000 ms

#include<bits/stdc++.h>
#define debug(x) cerr<<(#x)<<" "<<(x)<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe; 
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=5e5+9,INF=1e15;
ll n,X,Y,a[N][2],ans,b[N];
char typ[2];
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	n=read(),X=read(),Y=read();
	rep(i,1,n){
		ll x=read();
		scanf("%s",typ);
		if(typ[0]=='A')a[i%(X+Y)][0]+=x;
		else a[i%(X+Y)][1]+=x;
	}
	//选出 X 个 A, Y 个 B,sum 最大
	rep(i,1,X+Y)b[i]=a[i-1][1]-a[i-1][0];
	sort(b+1,b+X+Y+1);
	rep(i,0,X+Y-1)ans+=a[i][0];
	reverse(b+1,b+X+Y+1);
	rep(i,1,Y)ans+=b[i];
	write(ans);
	return 0;
}
0