結果

問題 No.2559 眩しい数直線
ユーザー Shogo_K
提出日時 2023-12-02 15:40:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 93,672 KB
最終ジャッジ日時 2025-02-18 04:49:41
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define INF 1e8

struct pair {
  int A, B;
};

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

  std::vector<pair> array(N);
  for (auto &&e: array) {
    std::cin >> e.A >> e.B;
  }

  // さて、計算
  std::vector<int> result(X);

  // 座標の数だけ計算
  for (int j = 0; j < X; j++) {

    int max = -INF;
    // 街灯の数だけ計算
    for (int i = 0; i < N; i++) {
      
      // 街灯 i の眩しさを計算
      int brightness = std::max(
        array[i].B - std::abs(j + 1 - array[i].A), 0
      );

      // 一番眩しいものを取得する
      if (max < brightness) {
        max = brightness;
      }
    }

    // 結果を格納する
    result.at(j) = max;
  }

  for (auto &&e: result) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
0