Submission #46827796


Source Code Expand

#include <bits/stdc++.h>

void solve(std::istream& is, std::ostream& os) {
    using Num = long long int;
    Num n {0};
    is >> n;

    std::vector<std::pair<Num, Num>> pre;
    for(Num i{0}; i<n; ++i) {
        Num t {0};
        Num d {0};
        is >> t >> d;
        pre.push_back(std::make_pair(t, t+d));
    }
    std::sort(pre.begin(), pre.end());

    Num answer {0};
    Num index {0};
    Num current = pre.begin()->first;
    std::priority_queue<Num, std::vector<Num>, std::greater<Num>> q;
    while(index < n) {
        if (q.empty()) {
            if (index < n) {
                current = std::max(current, pre.at(index).first);
            }
        }

        while(index < n) {
            if (pre.at(index).first <= current) {
                q.push(pre.at(index).second);
                ++index;
            } else {
                break;
            }
        }

        while (!q.empty()) {
            const auto t = q.top();
            q.pop();

            if (t >= current) {
                ++answer;
                ++current;
            }

            if (index < n) {
                if (current >= pre.at(index).first) {
                    break;
                }
            }
        }
    }

    os << answer << "\n";
    return;
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task D - Printing Machine
User zettsut
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1404 Byte
Status AC
Exec Time 160 ms
Memory 9904 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 47
Set Name Test Cases
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, 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, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 02_random2_20.txt, 02_random2_21.txt, 02_random2_22.txt, 02_random2_23.txt, 02_random2_24.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 03_random3_06.txt, 03_random3_07.txt, 03_random3_08.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3508 KiB
00_sample_01.txt AC 1 ms 3576 KiB
00_sample_02.txt AC 1 ms 3472 KiB
01_random_00.txt AC 160 ms 7348 KiB
01_random_01.txt AC 52 ms 4152 KiB
01_random_02.txt AC 116 ms 7292 KiB
01_random_03.txt AC 139 ms 7224 KiB
01_random_04.txt AC 110 ms 5404 KiB
02_random2_00.txt AC 137 ms 7296 KiB
02_random2_01.txt AC 147 ms 7848 KiB
02_random2_02.txt AC 144 ms 7748 KiB
02_random2_03.txt AC 148 ms 7948 KiB
02_random2_04.txt AC 143 ms 7808 KiB
02_random2_05.txt AC 136 ms 7236 KiB
02_random2_06.txt AC 145 ms 7308 KiB
02_random2_07.txt AC 146 ms 7252 KiB
02_random2_08.txt AC 144 ms 7240 KiB
02_random2_09.txt AC 142 ms 7360 KiB
02_random2_10.txt AC 135 ms 7256 KiB
02_random2_11.txt AC 144 ms 7296 KiB
02_random2_12.txt AC 142 ms 7352 KiB
02_random2_13.txt AC 141 ms 7216 KiB
02_random2_14.txt AC 137 ms 7252 KiB
02_random2_15.txt AC 133 ms 7236 KiB
02_random2_16.txt AC 140 ms 7224 KiB
02_random2_17.txt AC 140 ms 7368 KiB
02_random2_18.txt AC 138 ms 7316 KiB
02_random2_19.txt AC 136 ms 7312 KiB
02_random2_20.txt AC 116 ms 7364 KiB
02_random2_21.txt AC 115 ms 7352 KiB
02_random2_22.txt AC 114 ms 7312 KiB
02_random2_23.txt AC 112 ms 7220 KiB
02_random2_24.txt AC 112 ms 7348 KiB
03_random3_00.txt AC 124 ms 7396 KiB
03_random3_01.txt AC 127 ms 7260 KiB
03_random3_02.txt AC 125 ms 7356 KiB
03_random3_03.txt AC 122 ms 7296 KiB
03_random3_04.txt AC 123 ms 7252 KiB
03_random3_05.txt AC 126 ms 7356 KiB
03_random3_06.txt AC 124 ms 7256 KiB
03_random3_07.txt AC 123 ms 7252 KiB
03_random3_08.txt AC 124 ms 7224 KiB
04_handmade_00.txt AC 105 ms 9904 KiB
04_handmade_01.txt AC 113 ms 7364 KiB
04_handmade_02.txt AC 115 ms 7248 KiB
04_handmade_03.txt AC 1 ms 3508 KiB
04_handmade_04.txt AC 78 ms 9824 KiB