結果
| 問題 |
No.2623 Room Allocation
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-02-16 23:11:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 2,000 ms |
| コード長 | 1,202 bytes |
| コンパイル時間 | 689 ms |
| コンパイル使用メモリ | 47,744 KB |
| 実行使用メモリ | 9,412 KB |
| 最終ジャッジ日時 | 2024-09-28 21:47:51 |
| 合計ジャッジ時間 | 3,553 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:52:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
52 | auto [di, ui] = qs[i];
| ^
main.cpp:53:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
53 | auto [dj, uj] = qs[j];
| ^
main.cpp:60:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
60 | auto [di, ui] = qs[i];
| ^
main.cpp:64:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
64 | auto [dj, uj] = qs[j];
| ^
ソースコード
/* -*- coding: utf-8 -*-
*
* 2623.cc: No.2623 Room Allocation - yukicoder
*/
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MAX_X = 200000;
const int MAX_Y = 200000;
const int MAX_M = MAX_X + MAX_Y;
/* typedef */
typedef long long ll;
typedef pair<ll,int> pli;
/* global variables */
ll ps[MAX_N][2];
pli qs[MAX_N];
/* subroutines */
/* main */
int main() {
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
int m = x + y, k = min(n, m);
for (int i = 0; i < n; i++) {
int p;
char cs[4];
scanf("%d%s", &p, cs);
ps[i % m][cs[0] - 'A'] += p;
}
for (int i = 0; i < k; i++)
qs[i] = {ps[i][1] - ps[i][0], i};
sort(qs, qs + k);
ll sum = 0;
int i = 0, j = k - 1;
while (x > 0 && y > 0 && i <= j) {
auto [di, ui] = qs[i];
auto [dj, uj] = qs[j];
if (-di >= dj)
sum += ps[ui][0], x--, i++;
else
sum += ps[uj][1], y--, j--;
}
while (x > 0 && i <= j) {
auto [di, ui] = qs[i];
sum += ps[ui][0], x--, i++;
}
while (y > 0 && i <= j) {
auto [dj, uj] = qs[j];
sum += ps[uj][1], y--, j--;
}
printf("%lld\n", sum);
return 0;
}
tnakao0123