Submission #26052124


Source Code Expand

#include <algorithm>
#include <iostream>
#include <vector>

template <class T> std::vector<int> shrink_coordinate(std::vector<T> &a) {
  std::vector<T> b = a;

  std::sort(b.begin(), b.end());
  b.erase(std::unique(b.begin(), b.end()), b.end());

  int N = a.size();

  std::vector<int> res(N);
  for (int i = 0; i < N; i++) {
    res[i] = std::lower_bound(b.begin(), b.end(), a[i]) - b.begin();
  }

  return res;
}

int main() {
  int N, C;
  std::cin >> N >> C;

  std::vector<int> a(N), b(N), c(N);
  std::vector<int> x(2 * N);
  for (int i = 0; i < N; i++) {
    std::cin >> a[i] >> b[i] >> c[i];
    x[i] = a[i];
    x[i + N] = b[i] + 1;
  }

  std::vector<int> shrink_x = shrink_coordinate(x);

  std::vector<long long> prefix_sum(2 * N + 1, 0);
  for (int i = 0; i < N; i++) {
    prefix_sum[shrink_x[i]] += c[i];
    prefix_sum[shrink_x[i + N]] -= c[i];
  }

  for (int i = 1; i <= 2 * N; i++) {
    prefix_sum[i] += prefix_sum[i - 1];
  }

  std::sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());

  const int M = x.size();

  long long ans = 0;
  for (int i = 0; i < M - 1; i++) {
    long long cost = std::min(prefix_sum[i], (long long)C);
    long long days = x[i + 1] - x[i];

    ans += cost * days;
  }

  std::cout << ans << "\n";

  return 0;
}

Submission Info

Submission Time
Task D - Snuke Prime
User kira924age
Language C++ (GCC 9.2.1)
Score 400
Code Size 1346 Byte
Status AC
Exec Time 259 ms
Memory 11640 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 7 ms 3496 KiB
random_02.txt AC 2 ms 3508 KiB
random_03.txt AC 2 ms 3556 KiB
random_04.txt AC 4 ms 3520 KiB
random_05.txt AC 1 ms 3444 KiB
random_06.txt AC 2 ms 3560 KiB
random_07.txt AC 2 ms 3628 KiB
random_08.txt AC 2 ms 3440 KiB
random_09.txt AC 2 ms 3504 KiB
random_10.txt AC 2 ms 3448 KiB
random_11.txt AC 2 ms 3496 KiB
random_12.txt AC 2 ms 3560 KiB
random_13.txt AC 2 ms 3548 KiB
random_14.txt AC 2 ms 3404 KiB
random_15.txt AC 2 ms 3404 KiB
random_16.txt AC 74 ms 5604 KiB
random_17.txt AC 138 ms 7940 KiB
random_18.txt AC 119 ms 7280 KiB
random_19.txt AC 113 ms 7132 KiB
random_20.txt AC 239 ms 11516 KiB
random_21.txt AC 176 ms 9296 KiB
random_22.txt AC 33 ms 3904 KiB
random_23.txt AC 256 ms 11620 KiB
random_24.txt AC 259 ms 11576 KiB
random_25.txt AC 155 ms 11640 KiB
sample_01.txt AC 2 ms 3396 KiB
sample_02.txt AC 1 ms 3488 KiB
sample_03.txt AC 2 ms 3504 KiB