結果

問題 No.2623 Room Allocation
ユーザー 👑 chro_96chro_96
提出日時 2024-02-09 21:51:43
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,299 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 30,592 KB
実行使用メモリ 9,116 KB
最終ジャッジ日時 2024-02-09 21:51:48
合計ジャッジ時間 3,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 49 ms
8,760 KB
testcase_07 AC 48 ms
8,760 KB
testcase_08 AC 47 ms
7,608 KB
testcase_09 AC 48 ms
8,760 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 22 ms
9,116 KB
testcase_13 AC 22 ms
9,116 KB
testcase_14 RE -
testcase_15 AC 50 ms
6,676 KB
testcase_16 AC 15 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 49 ms
6,676 KB
testcase_19 AC 45 ms
6,676 KB
testcase_20 AC 47 ms
6,676 KB
testcase_21 AC 49 ms
6,676 KB
testcase_22 AC 37 ms
6,676 KB
testcase_23 AC 22 ms
6,676 KB
testcase_24 AC 48 ms
6,676 KB
testcase_25 AC 40 ms
6,676 KB
testcase_26 AC 7 ms
6,676 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 13 ms
7,224 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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[200000][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;
}
0