結果

問題 No.2623 Room Allocation
ユーザー planes
提出日時 2024-02-09 21:40:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 177,148 KB
実行使用メモリ 18,840 KB
最終ジャッジ日時 2024-09-28 14:55:49
合計ジャッジ時間 3,449 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;


int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll N,X,Y;cin>>N>>X>>Y;
  vector<ll> P(N),c(N);
  /*
  %Nで分けて考える
 0,1,2...N-1ごとにA,Bをふったときの人数が決まる人数が決まり,それにX,Yを割り振る.
  A-Bとすると,値が一つに決まる.おおきければAをふり,小さければBをふりたい.
  
  */


 for(ll i=0;i<N;i++) {
  cin>>P[i];
  char s;cin>>s;
  c[i]=s-'A';
 }

 ll M=(X+Y);

 vector<pair<ll,ll>> vec(M);

 for(ll i=0;i<N;i++) {
  ll k=i%M;
  if(c[i]==0) vec[k].first+=P[i];
  else vec[k].second+=P[i];
 }

 vector<pair<ll,ll>> note(M);
 for(ll i=0;i<M;i++) {
  note[i]=make_pair(vec[i].first-vec[i].second,i);
 }

 sort(all(note));
reverse(all(note));

vector<bool> memo(M);
for(ll i=0;i<X;i++) {
  memo[note[i].second]=true;
}


ll ans=0;
for(ll i=0;i<M;i++) {
  if(memo[i]) ans+=vec[i].first;
  else ans+=vec[i].second;
}

cout<<ans<<endl;
}



0