結果
| 問題 | No.2453 Seat Allocation | 
| コンテスト | |
| ユーザー |  srjywrdnprkt | 
| 提出日時 | 2023-08-19 22:48:30 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 266 ms / 2,000 ms | 
| コード長 | 1,135 bytes | 
| コンパイル時間 | 2,076 ms | 
| コンパイル使用メモリ | 202,332 KB | 
| 実行使用メモリ | 9,604 KB | 
| 最終ジャッジ日時 | 2025-06-20 01:43:04 | 
| 合計ジャッジ時間 | 6,522 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct fraction{
    ll p, q;
    fraction(ll P=0, ll Q=1) : p(P), q(Q) {
        if (Q < 0){
            p *= -1;
            q *= -1;
        }
    }
    bool operator < (const fraction & other) const{
        if (p < 0) return -p*other.q > -other.p*q;
        return p*other.q < other.p*q;
    }
    bool operator == (const fraction & other) const{
        return p*other.q == other.p*q;
    }
    bool operator > (const fraction & other) const{
        if (p < 0) return -p*other.q < -other.p*q;
        return p*other.q > other.p*q;
    }
};
int main(){
    ll N, M, x;
    fraction p;
    cin >> N >> M;
    vector<ll> A(N), B(M+1), cnt(N);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<M; i++) cin >> B[i];
    priority_queue<pair<fraction, ll>> que;
    for (int i=0; i<N; i++){
        que.push({fraction(A[i], B[cnt[0]]), -i});
    }
    while(M){
        M--;
        tie(p, x) = que.top();
        que.pop();
        cout << -x+1 << endl;
        cnt[-x]++;
        que.push({fraction(A[-x], B[cnt[-x]]), x});
    }
    return 0;
}
            
            
            
        