結果

問題 No.2453 Seat Allocation
ユーザー tnakao0123tnakao0123
提出日時 2023-09-11 15:20:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 56,156 KB
実行使用メモリ 5,448 KB
最終ジャッジ日時 2023-09-11 15:20:43
合計ジャッジ時間 3,069 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 49 ms
5,448 KB
testcase_06 AC 26 ms
4,380 KB
testcase_07 AC 15 ms
5,016 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 59 ms
5,448 KB
testcase_10 AC 59 ms
5,380 KB
testcase_11 AC 59 ms
5,380 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 28 ms
4,380 KB
testcase_14 AC 24 ms
4,384 KB
testcase_15 AC 33 ms
4,380 KB
testcase_16 AC 28 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 43 ms
4,380 KB
testcase_19 AC 50 ms
5,228 KB
testcase_20 AC 21 ms
4,380 KB
testcase_21 AC 27 ms
4,380 KB
testcase_22 AC 38 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2453.cc:  No.2453 Seat Allocation - yukicoder
 */

#include<cstdio>
#include<queue>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;

/* typedef */

typedef long long ll;

struct Cand {
  int i, j, a, b;
  Cand() {}
  Cand(int _i, int _j, int _a, int _b): i(_i), j(_j), a(_a), b(_b) {}

  bool operator<(const Cand &c) const {
    ll ab0 = (ll)a * c.b, ab1 = (ll)c.a * b;
    return ab0 < ab1 || (ab0 == ab1 && i > c.i);
  }
};

/* global variables */

int as[MAX_N], bs[MAX_M];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < m; i++) scanf("%d", bs + i);

  priority_queue<Cand> q;
  for (int i = 0; i < n; i++)
    q.push(Cand(i, 0, as[i], bs[0]));

  for (int k = 0; k < m; k++) {
    auto u = q.top(); q.pop();
    printf("%d\n", u.i + 1);

    if (u.j + 1 < m)
      q.push(Cand(u.i, u.j + 1, as[u.i], bs[u.j + 1]));
  }

  return 0;
}
0