結果

問題 No.3761 Moonlit Battle
コンテスト
ユーザー テナガザル
提出日時 2026-10-09 23:46:03
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,296 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,073 ms
コンパイル使用メモリ 186,920 KB
実行使用メモリ 31,652 KB
最終ジャッジ日時 2026-10-09 23:46:11
合計ジャッジ時間 7,610 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

int main()
{
  int n, d;
  cin >> n >> d;
  vector<pair<int, long long>> ba;
  {
    map<int, long long> ab;
    ab[0] = d + 1;
    for (int i = 0; i < n; ++i)
    {
      int a, b;
      cin >> a >> b;
      ab[b] += a;
    }
    for (auto [b, a] : ab) ba.push_back({b, a});
    reverse(ba.begin(), ba.end());
  }
  long long sum = 0;
  n = ba.size();
  int id = n;
  for (int i = 0; i < n; ++i)
  {
    sum += ba[i].second;
    if (sum >= d)
    {
      id = i;
      break;
    }
  }
  long long ans = 0;
  int tob = ba[id].first;
  for (int i = 0; i < id; ++i)
  {
    auto [b, a] = ba[i];
    long long c = (b - tob) / d;
    ans += c * ba[i].second;
    ba[i].first -= c * d;
  }
  map<int, long long> mp;
  for (int i = 0; i < n; ++i)
  {
    auto [b, a] = ba[i];
    mp[b] += a;
  }
  long long now = ans;
  ans = ans + max(mp.rbegin()->first, 0);
  int cnt = 0;
  while (mp.rbegin()->first >= 0)
  {
    auto itr = mp.end();
    --itr;
    int b = itr->first;
    int a = itr->second;
    mp.erase(mp.find(b));
    b -= d;
    mp[b] += a;
    now += a;
    ans = min(ans, now + max(mp.rbegin()->first, 0));
    ++cnt;
    if (cnt >= 5 * n) break;
  }
  cout << ans << endl;
}
0