Submission #46984602


Source Code Expand

#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using int64 = long long;
using uint = unsigned int;
using uint64 = unsigned long long;
bool ckmin(auto& a, auto b) { return b < a ? a = b, 1 : 0; }
bool ckmax(auto& a, auto b) { return b > a ? a = b, 1 : 0; }
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  multiset<pair<int64, int64>> s;
  for (int i = 0; i < n; i++) {
    int64 t, d;
    cin >> t >> d;
    s.insert({t, t + d});
  }
  int64 last = 0;
  int ans = 0;
  multiset<int64> s2;
  while (!s.empty() || !s2.empty()) {
    debug(s, s2, last, ans);
    if (!s2.empty()) {
      auto t = *s2.begin();
      if (last + 1 <= t) {
        ans++;
        last++;
      }
      s2.erase(s2.begin());
    } else {
      last = s.begin()->first - 1;
    }
    while (!s.empty() && s.begin()->first <= last + 1) {
      s2.insert(s.begin()->second);
      s.erase(s.begin());
    }
  }
  cout << ans << '\n';

  return 0;
}

Submission Info

Submission Time
Task D - Printing Machine
User xindubawukong
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1074 Byte
Status AC
Exec Time 186 ms
Memory 16012 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 3444 KiB
00_sample_01.txt AC 1 ms 3372 KiB
00_sample_02.txt AC 1 ms 3380 KiB
01_random_00.txt AC 133 ms 15220 KiB
01_random_01.txt AC 32 ms 7344 KiB
01_random_02.txt AC 91 ms 12168 KiB
01_random_03.txt AC 119 ms 13844 KiB
01_random_04.txt AC 84 ms 11696 KiB
02_random2_00.txt AC 137 ms 15968 KiB
02_random2_01.txt AC 170 ms 15952 KiB
02_random2_02.txt AC 180 ms 15968 KiB
02_random2_03.txt AC 186 ms 16008 KiB
02_random2_04.txt AC 185 ms 15876 KiB
02_random2_05.txt AC 133 ms 15880 KiB
02_random2_06.txt AC 169 ms 15952 KiB
02_random2_07.txt AC 170 ms 15932 KiB
02_random2_08.txt AC 167 ms 15952 KiB
02_random2_09.txt AC 165 ms 16000 KiB
02_random2_10.txt AC 137 ms 15980 KiB
02_random2_11.txt AC 161 ms 15812 KiB
02_random2_12.txt AC 154 ms 15872 KiB
02_random2_13.txt AC 156 ms 15936 KiB
02_random2_14.txt AC 156 ms 15812 KiB
02_random2_15.txt AC 135 ms 15948 KiB
02_random2_16.txt AC 150 ms 15956 KiB
02_random2_17.txt AC 149 ms 15868 KiB
02_random2_18.txt AC 154 ms 15884 KiB
02_random2_19.txt AC 155 ms 15936 KiB
02_random2_20.txt AC 128 ms 15928 KiB
02_random2_21.txt AC 132 ms 15856 KiB
02_random2_22.txt AC 129 ms 15880 KiB
02_random2_23.txt AC 130 ms 16000 KiB
02_random2_24.txt AC 122 ms 15936 KiB
03_random3_00.txt AC 134 ms 16012 KiB
03_random3_01.txt AC 138 ms 15864 KiB
03_random3_02.txt AC 133 ms 15860 KiB
03_random3_03.txt AC 126 ms 15980 KiB
03_random3_04.txt AC 143 ms 15856 KiB
03_random3_05.txt AC 134 ms 15952 KiB
03_random3_06.txt AC 136 ms 15860 KiB
03_random3_07.txt AC 138 ms 15880 KiB
03_random3_08.txt AC 128 ms 15884 KiB
04_handmade_00.txt AC 94 ms 16000 KiB
04_handmade_01.txt AC 122 ms 15948 KiB
04_handmade_02.txt AC 119 ms 15948 KiB
04_handmade_03.txt AC 1 ms 3472 KiB
04_handmade_04.txt AC 143 ms 15860 KiB