結果

問題 No.3761 Moonlit Battle
コンテスト
ユーザー ei1333333
提出日時 2026-09-10 03:06:56
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 192 ms / 2,000 ms
+ 112µs
コード長 661 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,533 ms
コンパイル使用メモリ 370,256 KB
実行使用メモリ 26,980 KB
最終ジャッジ日時 2026-10-09 20:50:21
合計ジャッジ時間 6,457 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  int N;
  ll D;
  cin >> N >> D;
  vector<pair<ll, ll> > V(N);
  ll total = 0;
  for (auto &[b, a]: V) {
    cin >> a >> b;
    total += a;
  }
  ranges::sort(V, greater());
  ll K = min(D, total);
  ll base = 0, cur = 0;
  map< ll, ll > events;
  for (auto [b, a]: V) {
    auto take = min(a, K);
    if (take == 0) break;
    base += take * (b / D);
    if (b % D != 0) {
      events[b % D] += take;
      cur += take;
    }
    K -= take;
  }
  ll add = cur;
  for (auto [r, cnt] : events) {
    cur -= cnt;
    add = min(add, r + cur);
  }
  cout << base + add << endl;
}
0