結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー やむなくやむなく
提出日時 2019-12-13 22:34:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,308 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 174,344 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 23:54:42
合計ジャッジ時間 38,926 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 473 ms
4,376 KB
testcase_01 AC 347 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 387 ms
4,376 KB
testcase_04 AC 431 ms
4,380 KB
testcase_05 AC 265 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 349 ms
4,376 KB
testcase_08 AC 367 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 274 ms
4,376 KB
testcase_19 AC 424 ms
4,384 KB
testcase_20 AC 273 ms
4,376 KB
testcase_21 AC 442 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 452 ms
4,380 KB
testcase_31 AC 455 ms
4,380 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 305 ms
4,376 KB
testcase_35 AC 881 ms
4,376 KB
testcase_36 WA -
testcase_37 AC 601 ms
4,380 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 836 ms
4,380 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 963 ms
4,376 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 671 ms
4,376 KB
testcase_53 AC 669 ms
4,376 KB
testcase_54 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct pizza{
    int p;
    int d;
};

unsigned long xor128(){
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<pizza> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].p >> v[i].d;
    }
    sort(v.begin(), v.end(), [](pizza &l, pizza &r){
        return l.p < r.p;
    });

    int ans = 0;
    int trial = 5000, get = 5000;
    for(int t = 0; t < trial; t++){
        vector<int> used(n, false);
        int now = 0;
        int tmp = 0;
        for(int i = 0; i < get; i++){
            int nxt = xor128() % n;
            if(!used[nxt] && v[nxt].p + now <= k){
                now += v[nxt].p;
                tmp += v[nxt].d;
                used[nxt] = true;
            }
        }
        priority_queue<int> q;
        for(int i = 0; i < n; i++){
            if(used[i]){
                if(!q.empty()){
                    tmp += q.top();
                    q.pop();
                }
            }else{
                q.push(v[i].d);
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}
0