結果

問題 No.2623 Room Allocation
ユーザー 👑 chro_96chro_96
提出日時 2024-02-09 21:52:54
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 16,444 KB
最終ジャッジ日時 2024-02-09 21:52:57
合計ジャッジ時間 2,595 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,272 KB
testcase_01 AC 4 ms
11,272 KB
testcase_02 AC 5 ms
11,272 KB
testcase_03 AC 5 ms
11,272 KB
testcase_04 AC 4 ms
11,272 KB
testcase_05 AC 5 ms
11,272 KB
testcase_06 AC 49 ms
13,448 KB
testcase_07 AC 44 ms
13,448 KB
testcase_08 AC 43 ms
12,296 KB
testcase_09 AC 44 ms
13,448 KB
testcase_10 AC 37 ms
16,444 KB
testcase_11 AC 38 ms
16,444 KB
testcase_12 AC 19 ms
13,804 KB
testcase_13 AC 20 ms
13,804 KB
testcase_14 AC 80 ms
16,444 KB
testcase_15 AC 43 ms
11,272 KB
testcase_16 AC 15 ms
11,272 KB
testcase_17 AC 5 ms
11,272 KB
testcase_18 AC 51 ms
11,272 KB
testcase_19 AC 46 ms
11,272 KB
testcase_20 AC 44 ms
11,272 KB
testcase_21 AC 43 ms
11,272 KB
testcase_22 AC 35 ms
11,272 KB
testcase_23 AC 21 ms
11,272 KB
testcase_24 AC 44 ms
11,272 KB
testcase_25 AC 35 ms
11,272 KB
testcase_26 AC 7 ms
11,272 KB
testcase_27 AC 98 ms
16,148 KB
testcase_28 AC 44 ms
14,136 KB
testcase_29 AC 30 ms
13,876 KB
testcase_30 AC 90 ms
15,804 KB
testcase_31 AC 12 ms
11,912 KB
testcase_32 AC 29 ms
15,572 KB
権限があれば一括ダウンロードができます

ソースコード

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