結果
| 問題 |
No.2623 Room Allocation
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2024-02-09 21:52:54 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 102 ms / 2,000 ms |
| コード長 | 1,299 bytes |
| コンパイル時間 | 535 ms |
| コンパイル使用メモリ | 30,720 KB |
| 実行使用メモリ | 17,416 KB |
| 最終ジャッジ日時 | 2024-09-28 15:08:46 |
| 合計ジャッジ時間 | 2,864 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
int cmp_ll_rev (const void *ap, const void *bp) {
long long a = *(long long *)ap;
long long b = *(long long *)bp;
if (a < b) {
return 1;
}
if (a > b) {
return -1;
}
return 0;
}
int main () {
int n = 0;
int x = 0;
int y = 0;
long long p = 0LL;
char c = '\0';
int res = 0;
long long ans = 0LL;
long long sum[400000][3] = {};
int cnt[2] = {};
res = scanf("%d", &n);
res = scanf("%d", &x);
res = scanf("%d", &y);
for (int i = 0; i < n; i++) {
res = scanf("%lld", &p);
res = scanf("%c", &c);
res = scanf("%c", &c);
if (c == 'A') {
sum[i%(x+y)][1] += p;
} else {
sum[i%(x+y)][2] += p;
}
}
for (int i = 0; i < x+y; i++) {
if (sum[i][1] < sum[i][2]) {
sum[i][0] = sum[i][2]-sum[i][1];
} else {
sum[i][0] = sum[i][1]-sum[i][2];
}
}
qsort(sum, x+y, sizeof(long long)*3, cmp_ll_rev);
for (int i = 0; i < x+y; i++) {
if (sum[i][1] < sum[i][2] && cnt[1] < y) {
ans += sum[i][2];
cnt[1]++;
} else if (sum[i][1] < sum[i][2]) {
ans += sum[i][1];
} else if (cnt[0] < x) {
ans += sum[i][1];
cnt[0]++;
} else {
ans += sum[i][2];
}
}
printf("%lld\n", ans);
return 0;
}
chro_96