提出 #67720539


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using u64 = unsigned long long;

class Solution {
public:
    void solve() {

        u64 N; int M;
        cin>>N>>M;
        vector<pair<u64,u64>> V;
        V.reserve(M);
        for(int i=0;i<M;i++){
            u64 A,B;cin>>A>>B;
            if(A<=N) V.emplace_back(A,A-B);
        }
        sort(V.begin(),V.end());

        vector<pair<u64,u64>> heap;
        __uint128_t E=N;
        u64 ans=0;
        int i=0, K=V.size();

        auto cmp = [](auto &a, auto &b){ return a.second > b.second; };

        while(i<K && V[i].first<=E){
            heap.push_back(V[i++]);
            push_heap(heap.begin(), heap.end(), cmp);
        }
        while(!heap.empty()){
            pop_heap(heap.begin(), heap.end(), cmp);
            auto [A,C]=heap.back();
            heap.pop_back();
            if(E<A) continue;
            __uint128_t t=(E-A)/C+1;
            ans+=(u64)t;
            E-=t*C;
        }
        cout<<ans<<"\n";
    }
};

int main(){
    Solution *s=new Solution();
    s->solve();
    return 0;
}

提出情報

提出日時
問題 D - Get Many Stickers
ユーザ Naman____17
言語 C++ 17 (Clang 16.0.6)
得点 400
コード長 1117 Byte
結果 AC
実行時間 197 ms
メモリ 10524 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 31
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3516 KiB
00_sample_01.txt AC 1 ms 3516 KiB
00_sample_02.txt AC 1 ms 3644 KiB
01_random_00.txt AC 93 ms 6544 KiB
01_random_01.txt AC 131 ms 7096 KiB
01_random_02.txt AC 144 ms 6468 KiB
01_random_03.txt AC 94 ms 10452 KiB
01_random_04.txt AC 94 ms 10268 KiB
01_random_05.txt AC 94 ms 10488 KiB
02_random2_00.txt AC 144 ms 10460 KiB
02_random2_01.txt AC 145 ms 10364 KiB
02_random2_02.txt AC 144 ms 10504 KiB
02_random2_03.txt AC 129 ms 10512 KiB
02_random2_04.txt AC 129 ms 10480 KiB
02_random2_05.txt AC 130 ms 10464 KiB
02_random2_06.txt AC 157 ms 10384 KiB
02_random2_07.txt AC 156 ms 10436 KiB
02_random2_08.txt AC 156 ms 10484 KiB
02_random2_09.txt AC 193 ms 10272 KiB
02_random2_10.txt AC 196 ms 10524 KiB
02_random2_11.txt AC 197 ms 10388 KiB
03_random3_00.txt AC 193 ms 10380 KiB
03_random3_01.txt AC 193 ms 10448 KiB
03_random3_02.txt AC 194 ms 10292 KiB
03_random3_03.txt AC 194 ms 10356 KiB
03_random3_04.txt AC 194 ms 10312 KiB
04_handmade_00.txt AC 33 ms 3492 KiB
04_handmade_01.txt AC 44 ms 10412 KiB
04_handmade_02.txt AC 1 ms 3468 KiB
04_handmade_03.txt AC 1 ms 3464 KiB
04_handmade_04.txt AC 175 ms 10452 KiB