結果
問題 |
No.2623 Room Allocation
|
ユーザー |
![]() |
提出日時 | 2023-12-28 20:38:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 1,014 bytes |
コンパイル時間 | 1,026 ms |
コンパイル使用メモリ | 80,796 KB |
最終ジャッジ日時 | 2025-02-18 14:59:06 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <algorithm> #include <cassert> #include <iostream> #include <vector> using namespace std; int main() { int N, X, Y; cin >> N >> X >> Y; assert(N >= 1 && N <= 200000); assert(X >= 0 && X <= 200000); assert(Y >= 0 && Y <= 200000); assert(X + Y >= 1); vector<long long> P(N); vector<char> c(N); long long all_people = 0; for (int i = 0; i < N; i++) { cin >> P[i] >> c[i]; assert(P[i] >= 1 && P[i] <= 1000000000); assert(c[i] == 'A' || c[i] == 'B'); all_people += P[i]; } vector<long long> groups(X + Y, 0); for (int i = 0; i < N; i++) { if (c[i] == 'A') { groups[i % (X + Y)] += P[i]; } else { groups[i % (X + Y)] -= P[i]; } } sort(groups.begin(), groups.end()); long long ans = 0; for (int i = 0; i < Y; i++) { ans -= groups[i]; } for (int i = Y; i < X + Y; i++) { ans += groups[i]; } cout << (ans + all_people) / 2 << endl; }